結果
問題 | No.307 最近色塗る問題多くない? |
ユーザー |
|
提出日時 | 2016-03-01 23:28:52 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 260 ms / 4,000 ms |
コード長 | 1,288 bytes |
コンパイル時間 | 912 ms |
コンパイル使用メモリ | 72,940 KB |
実行使用メモリ | 7,296 KB |
最終ジャッジ日時 | 2024-11-21 22:14:44 |
合計ジャッジ時間 | 3,483 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 36 |
ソースコード
#include <iostream> #include <vector> #include <deque> #include <functional> #define repeat(i,n) for (int i = 0; (i) < (n); ++(i)) using namespace std; const int dy[] = { -1, 1, 0, 0 }; const int dx[] = { 0, 0, 1, -1 }; int main() { int h, w; cin >> h >> w; vector<deque<bool> > a(h, deque<bool>(w)); repeat (y,h) repeat (x,w) cin >> a[y][x]; int q; cin >> q; bool trivial = false; repeat (query,q) { int y, x, p; cin >> y >> x >> p; -- y; -- x; if (trivial) { if (query == q-1) { repeat (y,h) repeat (x,w) a[y][x] = p; } } else { int cnt = 0; function<void (int,int)> dfs = [&](int y, int x) { a[y][x] = p; cnt += 1; repeat (i,4) { int ny = y + dy[i]; int nx = x + dx[i]; if (ny < 0 or h <= ny or nx < 0 or w <= nx) continue; if (a[ny][nx] != p) dfs(ny, nx); } }; if (a[y][x] != p) dfs(y,x); if (cnt == h * w) trivial = true; } } repeat (y,h) { repeat (x,w) { if (x) cout << ' '; cout << a[y][x]; } cout << endl; } return 0; }