結果

提出番号 1361
提出者 E869120
言語 C++
提出日時 2018-07-20 16:56:10
問題名 (65)Small Grid and Score
結果 AC
点数 100%

テストケース

テストケース 結果 得点 実行時間 メモリ使用量
1 AC 92% 2ms 7824KB
2 AC 92% 3ms 7472KB
3 AC 92% 2ms 8368KB
4 AC 92% 4ms 8336KB
5 AC 92% 3ms 8112KB
6 AC 92% 4ms 8688KB
7 AC 92% 4ms 7520KB
8 AC 92% 3ms 8416KB
9 AC 92% 5ms 8176KB
10 AC 92% 5ms 8400KB
11 AC 92% 3ms 8688KB
12 AC 92% 2ms 8432KB
13 AC 92% 2ms 7520KB
14 AC 92% 3ms 7776KB
15 AC 92% 2ms 8432KB
16 AC 92% 2ms 7520KB
17 AC 92% 6ms 7776KB
18 AC 92% 2ms 8720KB
19 AC 92% 1ms 7872KB
20 AC 92% 2ms 8656KB
21 AC 92% 2ms 8048KB
22 AC 92% 2ms 8256KB
23 AC 92% 2ms 8352KB
24 AC 92% 2ms 8384KB
テストケース 結果 得点 実行時間 メモリ使用量
25 AC 92% 119ms 7600KB
26 AC 92% 129ms 8272KB
27 AC 92% 72ms 8672KB
28 AC 92% 101ms 8128KB
29 AC 92% 71ms 8432KB
30 AC 92% 17ms 7632KB
31 AC 92% 123ms 8144KB
32 AC 92% 15ms 8416KB
33 AC 92% 152ms 8416KB
34 AC 92% 170ms 7840KB
35 AC 92% 40ms 8688KB
36 AC 92% 18ms 8240KB
37 AC 92% 100ms 8416KB
38 AC 92% 144ms 8016KB
39 AC 92% 36ms 8352KB
40 AC 92% 68ms 8400KB
41 AC 92% 168ms 7984KB
42 AC 92% 23ms 7872KB
43 AC 92% 167ms 7792KB
44 AC 92% 47ms 8416KB
45 AC 92% 48ms 7856KB
46 AC 92% 13ms 8704KB
47 AC 92% 63ms 8544KB
48 AC 92% 52ms 7824KB
49 AC 92% 10ms 8208KB
50 AC 92% 157ms 8656KB
51 AC 92% 18ms 8400KB
52 AC 92% 205ms 7888KB
53 AC 92% 12ms 7824KB
54 AC 92% 126ms 8672KB
55 AC 92% 46ms 8304KB
56 AC 92% 39ms 7648KB
57 AC 92% 33ms 8000KB
58 AC 92% 111ms 8432KB
59 AC 92% 17ms 7840KB
60 AC 92% 44ms 8128KB
61 AC 92% 33ms 8400KB
62 AC 92% 74ms 8272KB
63 AC 92% 39ms 7536KB
64 AC 92% 81ms 7936KB
65 AC 92% 119ms 7504KB
66 AC 92% 208ms 8192KB
67 AC 92% 64ms 7984KB
68 AC 92% 62ms 7536KB
69 AC 92% 129ms 8480KB
70 AC 92% 9ms 8416KB
71 AC 92% 80ms 8432KB
72 AC 92% 29ms 8352KB
73 AC 92% 17ms 8432KB
74 AC 92% 59ms 8432KB
75 AC 92% 23ms 8080KB
76 AC 92% 44ms 8128KB
77 AC 92% 23ms 8256KB
78 AC 92% 92ms 8736KB
79 AC 92% 196ms 7984KB
80 AC 92% 28ms 8416KB
81 AC 92% 25ms 8480KB
82 AC 92% 120ms 8416KB
83 AC 92% 87ms 7968KB
84 AC 92% 126ms 8688KB
85 AC 92% 105ms 8720KB
86 AC 92% 136ms 8704KB
87 AC 92% 86ms 8384KB
88 AC 92% 158ms 7616KB
89 AC 92% 113ms 8272KB
90 AC 92% 170ms 8064KB
91 AC 92% 88ms 8720KB
92 AC 92% 8ms 8720KB
93 AC 92% 56ms 8416KB
94 AC 92% 71ms 8736KB
95 AC 92% 16ms 7888KB
96 AC 92% 35ms 8672KB
97 AC 92% 132ms 8448KB
98 AC 92% 108ms 8432KB
99 AC 92% 6ms 8432KB
100 AC 92% 19ms 8416KB
101 AC 92% 27ms 8656KB
102 AC 92% 33ms 7648KB
103 AC 92% 84ms 8704KB
104 AC 92% 29ms 8368KB
105 AC 92% 33ms 8400KB
106 AC 92% 16ms 8256KB
107 AC 92% 65ms 8048KB
108 AC 92% 168ms 8400KB
109 AC 92% 141ms 8368KB
110 AC 92% 150ms 8112KB
111 AC 92% 16ms 8704KB
112 AC 92% 122ms 8448KB
113 AC 92% 50ms 8080KB
114 AC 92% 29ms 8400KB
115 AC 92% 206ms 7984KB
116 AC 92% 42ms 7968KB
117 AC 92% 134ms 8720KB
118 AC 92% 14ms 7792KB
119 AC 92% 142ms 7520KB
120 AC 92% 84ms 7808KB
121 AC 92% 16ms 8240KB
122 AC 92% 161ms 8416KB
123 AC 92% 141ms 8656KB
124 AC 92% 106ms 7520KB

ソースコード

#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
using namespace std;

int Rand(int p, int q) {
	int s = 0, t = 1;
	for (int i = 0; i < 3; i++) { s += (rand() % 1024)*t; t *= 1024; }
	return p + s % (q - p + 1);
}

long long dp[44][44], dp2[44][44], dpr[44][44];

pair<vector<string>, long long> solve(long long N) {
	for (int i = 0; i < 44; i++) {
		for (int j = 0; j < 44; j++) {
			if (i == 0 || j == 0) dpr[i][j] = 1;
			else dpr[i][j] = dpr[i - 1][j] + dpr[i][j - 1];
		}
	}
	for (int i = 2; i < 44; i++) {
		long long H = i / 2, W = (i + 1) / 2;

		for (int j = 1; j <= 500; j++) {
			vector<string>F(H, "");
			for (int j = 0; j < H; j++) { for (int k = 0; k < W; k++) F[j] += "."; }

			long long S = Rand(H * W / 2, H * W * 4 / 5 + 1);
			for (int k = 1; k <= S; k++) {
				while (true) {
					int px = Rand(0, H - 1), py = Rand(0, W - 1); if (px <= 3 && py >= 16 && Rand(0, 1) == 1) continue;
					if (F[px][py] == '.') { F[px][py] = '2'; break; }
				}
			}
			bool OK = false; dp[0][0] = 1; if (F[0][0] == '2') dp[0][0] = 2;
			for (int k = 0; k < H; k++) {
				for (int l = 0; l < W; l++) {
					if (k == 0 && l == 0) continue;
					dp[k][l] = 0;
					if (k >= 1) dp[k][l] += dp[k - 1][l];
					if (l >= 1) dp[k][l] += dp[k][l - 1];
					if (F[k][l] == '2') dp[k][l] *= 2;
					if (dp[k][l] > N) { OK = true; break; }
				}
			}
			if (OK == true || !(N * 5 / 6 <= dp[H - 1][W - 1] && dp[H - 1][W - 1] <= N)) continue;

			dp2[H - 1][W - 1] = 1; if (F[H - 1][W - 1] == '2') dp2[H - 1][W - 1] = 2;
			for (int k = H - 1; k >= 0; k--) {
				for (int l = W - 1; l >= 0; l--) {
					if (k == H - 1 && l == W - 1) continue;
					dp2[k][l] = 0;
					if (k < H - 1) dp2[k][l] += dp2[k + 1][l];
					if (l < W - 1) dp2[k][l] += dp2[k][l + 1];
					if (F[k][l] == '2') dp2[k][l] *= 2;
				}
			}
			long long A = N - dp[H - 1][W - 1];
			vector<tuple<long long, int, int>>vec;
			for (int k = 0; k < H; k++) {
				for (int l = 0; l < W; l++) { if (F[k][l] == '.') vec.push_back(make_tuple(dpr[k][l] * dp2[k][l], k, l)); }
			}
			sort(vec.begin(), vec.end()); reverse(vec.begin(), vec.end());
			for (int k = 0; k < vec.size(); k++) {
				if (A >= get<0>(vec[k])) { F[get<1>(vec[k])][get<2>(vec[k])] = '1'; A -= get<0>(vec[k]); }
			}
			long long SS = 0, V = A;
			while (A >= 2) { if (A % 2 == 1) SS++; A /= 2; SS++; }
			if (SS <= (H + W + 1)) {
				return make_pair(F, V);
			}
		}
	}
	return make_pair(vector<string>{""}, -1);
}

char c[60][60];

void getans(long long N) {
	for (int i = 0; i < 60; i++) { for (int j = 0; j < 60; j++) c[i][j] = '#'; }
	pair<vector<string>, int>C = solve(N);

	int H = C.first.size(), W = C.first[0].size();
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) { c[i][j + 2] = C.first[i][j]; }
	}
	for (int i = 0; i < H + 2; i++) c[i][0] = '.'; c[0][1] = '.'; c[H][W + 1] = '.';
	for (int i = 0; i < W + 2; i++) c[H + 1][i] = '.';

	vector<int>G; long long V = C.second;
	while (V >= 2) { if (V % 2 == 1) { G.push_back(1); V--; } G.push_back(2); V /= 2; }
	reverse(G.begin(), G.end());

	if (V == 0) { c[1][0] = '#'; }

	int cx = 1, cy = 0;
	for (int i = 0; i < G.size(); i++) { c[cx][cy] = ('0' + G[i]); if (cx < H + 1) cx++; else cy++; }

	cout << H + 2 << " " << W + 2 << endl;
	for (int i = 0; i < H + 2; i++) {
		for (int j = 0; j < W + 2; j++) cout << c[i][j]; cout << endl;
	}
}

int main() {
	long long n; cin >> n;
	if (n == 0) {
		cout << "1 1" << endl;
		cout << "#" << endl;
		return 0;
	}
	getans(n);
	return 0;
}