結果

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

テストケース

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

ソースコード

#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 (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) {
	bool OK = false; if (N % 2 == 0) { N /= 2; OK = true; }
	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++; }
	if (OK == true) c[0][0] = '2';

	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;
}