結果
問題 | No.2641 draw X |
ユーザー | InTheBloom |
提出日時 | 2024-02-26 00:39:09 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 163 ms / 2,000 ms |
コード長 | 4,891 bytes |
コンパイル時間 | 1,498 ms |
コンパイル使用メモリ | 102,732 KB |
実行使用メモリ | 65,280 KB |
最終ジャッジ日時 | 2024-09-29 11:30:52 |
合計ジャッジ時間 | 5,256 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 2 ms
6,820 KB |
testcase_03 | AC | 2 ms
6,820 KB |
testcase_04 | AC | 2 ms
6,816 KB |
testcase_05 | AC | 2 ms
6,816 KB |
testcase_06 | AC | 2 ms
6,820 KB |
testcase_07 | AC | 2 ms
6,816 KB |
testcase_08 | AC | 2 ms
6,820 KB |
testcase_09 | AC | 1 ms
6,820 KB |
testcase_10 | AC | 2 ms
6,816 KB |
testcase_11 | AC | 1 ms
6,816 KB |
testcase_12 | AC | 2 ms
6,816 KB |
testcase_13 | AC | 1 ms
6,816 KB |
testcase_14 | AC | 2 ms
6,816 KB |
testcase_15 | AC | 128 ms
65,280 KB |
testcase_16 | AC | 150 ms
65,152 KB |
testcase_17 | AC | 1 ms
6,820 KB |
testcase_18 | AC | 2 ms
6,820 KB |
testcase_19 | AC | 1 ms
6,820 KB |
testcase_20 | AC | 12 ms
7,552 KB |
testcase_21 | AC | 24 ms
12,800 KB |
testcase_22 | AC | 10 ms
7,296 KB |
testcase_23 | AC | 19 ms
11,392 KB |
testcase_24 | AC | 8 ms
6,816 KB |
testcase_25 | AC | 7 ms
6,816 KB |
testcase_26 | AC | 25 ms
13,312 KB |
testcase_27 | AC | 7 ms
6,816 KB |
testcase_28 | AC | 47 ms
24,520 KB |
testcase_29 | AC | 99 ms
50,780 KB |
testcase_30 | AC | 90 ms
43,096 KB |
testcase_31 | AC | 68 ms
29,776 KB |
testcase_32 | AC | 116 ms
51,128 KB |
testcase_33 | AC | 116 ms
50,708 KB |
testcase_34 | AC | 67 ms
30,524 KB |
testcase_35 | AC | 56 ms
27,260 KB |
testcase_36 | AC | 139 ms
58,624 KB |
testcase_37 | AC | 153 ms
62,208 KB |
testcase_38 | AC | 138 ms
54,656 KB |
testcase_39 | AC | 163 ms
64,384 KB |
testcase_40 | AC | 149 ms
61,056 KB |
testcase_41 | AC | 126 ms
54,912 KB |
testcase_42 | AC | 147 ms
58,240 KB |
testcase_43 | AC | 141 ms
55,680 KB |
ソースコード
#include <iostream> #include <vector> #include <string> using namespace std; void solve (int H, int W, vector<string>& S) { // 場所からできるだけデカいバツを書いていったとき、同じになるか? enum direction { left_up, left_down, right_up, right_down, }; vector<vector<vector<int>>> maximum_stretch(H, vector<vector<int>>(W, vector<int>(4))); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (S[i][j] == '.') maximum_stretch[i][j][left_up] = -1; if (S[i][j] == '#') { if (i == 0 || j == 0) { maximum_stretch[i][j][left_up] = 0; } else { maximum_stretch[i][j][left_up] = maximum_stretch[i-1][j-1][left_up] + 1; } } } } for (int i = H-1; 0 <= i; i--) { for (int j = 0; j < W; j++) { if (S[i][j] == '.') maximum_stretch[i][j][left_down] = -1; if (S[i][j] == '#') { if (i == H-1 || j == 0) { maximum_stretch[i][j][left_down] = 0; } else { maximum_stretch[i][j][left_down] = maximum_stretch[i+1][j-1][left_down] + 1; } } } } for (int i = 0; i < H; i++) { for (int j = W-1; 0 <= j; j--) { if (S[i][j] == '.') maximum_stretch[i][j][right_up] = -1; if (S[i][j] == '#') { if (i == 0 || j == W-1) { maximum_stretch[i][j][right_up] = 0; } else { maximum_stretch[i][j][right_up] = maximum_stretch[i-1][j+1][right_up] + 1; } } } } for (int i = H-1; 0 <= i; i--) { for (int j = W-1; 0 <= j; j--) { if (S[i][j] == '.') maximum_stretch[i][j][right_down] = -1; if (S[i][j] == '#') { if (i == H-1 || j == W-1) { maximum_stretch[i][j][right_down] = 0; } else { maximum_stretch[i][j][right_down] = maximum_stretch[i+1][j+1][right_down] + 1; } } } } vector<string> T(H, string(W, 0)); vector<vector<int>> draw_table(H, vector<int>(W)); for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) draw_table[i][j] = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (S[i][j] == '.') T[i][j] = '.'; if (S[i][j] == '#') { int len = H*W; for (int k = 0; k < 4; k++) len = min(len, maximum_stretch[i][j][k]); if (len == 0) continue; draw_table[i-len][j-len] += 1; if (i+len+1 < H && j+len+1 < W) draw_table[i+len+1][j+len+1] += -1; } } } // 塗る for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) { if (0 < i && 0 < j) draw_table[i][j] += draw_table[i-1][j-1]; if (T[i][j] == '#') continue; if (0 < draw_table[i][j]) { T[i][j] = '#'; } else { T[i][j] = '.'; } } for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) draw_table[i][j] = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (S[i][j] == '.') T[i][j] = '.'; if (S[i][j] == '#') { int len = H*W; for (int k = 0; k < 4; k++) len = min(len, maximum_stretch[i][j][k]); if (len == 0) continue; draw_table[i+len][j-len] += 1; if (0 <= i-len-1 && j+len+1 < W) draw_table[i-len-1][j+len+1] += -1; } } } // 塗る for (int i = H-1; 0 <= i; i--) for (int j = 0; j < W; j++) { if (i < H-1 && 0 < j) draw_table[i][j] += draw_table[i+1][j-1]; if (T[i][j] == '#') continue; if (0 < draw_table[i][j]) { T[i][j] = '#'; } else { T[i][j] = '.'; } } bool ok = true; for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) if (S[i][j] != T[i][j]) ok = false; /* visualize for (int k = 0; k < 4; k++) { for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { cout << maximum_stretch[i][j][k] << " "; } cout << "\n"; } cout << "\n"; } for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { cout << T[i][j]; } cout << "\n"; } // */ if (ok) { cout << "Yes\n"; } else { cout << "No\n"; } } int main () { int H, W; cin >> H >> W; vector<string> S(H); for (int i = 0; i < H; i++) cin >> S[i]; solve(H, W, S); }