結果

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

テストケース

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

ソースコード

#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 <= 100; 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 * 2 / 3 + 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) {
	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;
}