結果
問題 | No.2641 draw X |
ユーザー |
![]() |
提出日時 | 2024-02-20 21:15:46 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 2,268 bytes |
コンパイル時間 | 685 ms |
コンパイル使用メモリ | 62,672 KB |
実行使用メモリ | 814,208 KB |
最終ジャッジ日時 | 2024-09-29 03:52:21 |
合計ジャッジ時間 | 3,300 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 MLE * 1 -- * 15 |
ソースコード
/* -*- coding: utf-8 -*- * * 2641.cc: No.2641 draw X - yukicoder */ #include<cstdio> #include<vector> #include<algorithm> #include<utility> using namespace std; /* constant */ const int MAX_HW = 1000000; /* typedef */ typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> pii; typedef vector<pii> vpii; typedef vector<vpii> vvpii; /* global variables */ char s[MAX_HW + 4], t[MAX_HW + 4]; /* subroutines */ /* main */ int main() { int h, w; scanf("%d%d", &h, &w); int hw = h * w; for (int i = 0; i < h; i++) scanf("%s", s + i * w); int m = h + w - 1; vvpii ps0(m, vpii()), ps1(m, vpii()); for (int i = 0; i < m; i++) { int x0 = max(0, i - (h - 1)), x1 = min(w - 1, i) + 1; // y + x = i -> y = i - x for (int r = x0; r < x1;) { while (r < x1 && s[(i - r) * w + r] == '.') r++; if (r >= x1) break; int l = r; while (r < x1 && s[(i - r) * w + r] == '#') r++; ps0[i].push_back({r - 1, l}); } // (h - 1 - y) + x = i -> y = (h - 1) - (i - x) for (int r = x0; r < x1;) { while (r < x1 && s[(h - 1 - (i - r)) * w + r] == '.') r++; if (r >= x1) break; int l = r; while (r < x1 && s[(h - 1 - (i - r)) * w + r] == '#') r++; ps1[i].push_back({r - 1, l}); } } vvi cs0(m, vi(w + 1, 0)), cs1(m, vi(w + 1, 0)); for (int y = 1; y < h - 1; y++) for (int x = 1; x < w - 1; x++) if (s[y * w + x] == '#') { int i0 = y + x, i1 = (h - 1 - y) + x; auto vit0 = lower_bound(ps0[i0].begin(), ps0[i0].end(), pii(x, -1)); auto vit1 = lower_bound(ps1[i1].begin(), ps1[i1].end(), pii(x, -1)); int r = min(min(x - vit0->second, vit0->first - x), min(x - vit1->second, vit1->first - x)); if (r > 0) { cs0[i0][x - r]++, cs0[i0][x + r + 1]--; cs1[i1][x - r]++, cs1[i1][x + r + 1]--; } } fill(t, t + hw, '.'); for (int i = 0; i < m; i++) { for (int x = 0; x < w; x++) { if (cs0[i][x] > 0) t[(i - x) * w + x] = '#'; cs0[i][x + 1] += cs0[i][x]; } for (int x = 0; x < w; x++) { if (cs1[i][x] > 0) t[(h - 1 - (i - x)) * w + x] = '#'; cs1[i][x + 1] += cs1[i][x]; } } for (int i = 0; i < hw; i++) if (s[i] != t[i]) { puts("No"); return 0; } puts("Yes"); return 0; }