結果
問題 | No.2641 draw X |
ユーザー | InTheBloom |
提出日時 | 2024-02-26 00:28:08 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 4,877 bytes |
コンパイル時間 | 1,176 ms |
コンパイル使用メモリ | 101,264 KB |
実行使用メモリ | 64,000 KB |
最終ジャッジ日時 | 2024-09-29 11:30:47 |
合計ジャッジ時間 | 11,428 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,820 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | AC | 1 ms
6,816 KB |
testcase_05 | AC | 1 ms
6,816 KB |
testcase_06 | AC | 1 ms
6,820 KB |
testcase_07 | AC | 1 ms
6,820 KB |
testcase_08 | AC | 2 ms
6,816 KB |
testcase_09 | AC | 1 ms
6,816 KB |
testcase_10 | AC | 1 ms
6,820 KB |
testcase_11 | AC | 2 ms
6,820 KB |
testcase_12 | AC | 2 ms
6,820 KB |
testcase_13 | AC | 2 ms
6,820 KB |
testcase_14 | AC | 1 ms
6,820 KB |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | AC | 2 ms
6,820 KB |
testcase_18 | AC | 2 ms
6,820 KB |
testcase_19 | AC | 1 ms
6,820 KB |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | RE | - |
testcase_38 | RE | - |
testcase_39 | RE | - |
testcase_40 | RE | - |
testcase_41 | RE | - |
testcase_42 | RE | - |
testcase_43 | RE | - |
ソースコード
#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); 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); }