結果
問題 |
No.307 最近色塗る問題多くない?
|
ユーザー |
|
提出日時 | 2015-12-02 18:14:10 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,287 bytes |
コンパイル時間 | 1,049 ms |
コンパイル使用メモリ | 76,364 KB |
実行使用メモリ | 817,636 KB |
最終ジャッジ日時 | 2024-09-14 08:00:37 |
合計ジャッジ時間 | 7,102 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 4 MLE * 1 -- * 31 |
ソースコード
#include <iostream> #include <cstdio> #include <vector> #include <utility> #include <queue> using namespace std; const int dr[4] = {1, 0, -1, 0}; const int dc[4] = {0, 1, 0, -1}; int h, w, q; vector< vector<int> > a; void paint(int r, int c, int x) { vector< vector<bool> > painted(h, vector<bool>(w, false)); int base_color = a[r][c]; if (base_color == x) { return; } queue<pair<int, int> > que; que.push(make_pair(r, c)); while (!que.empty()) { auto pos = que.front(); que.pop(); a[pos.first][pos.second] = x; painted[pos.first][pos.second] = true; for (int i = 0; i < 4; i++) { int nr = pos.first + dr[i]; int nc = pos.second + dc[i]; if (nr < 0 || h <= nr || nc < 0 || w <= nc) { continue; } if (painted[nr][nc]) { continue; } if (a[nr][nc] != base_color) { continue; } que.push(make_pair(nr, nc)); } } } int main() { cin >> h >> w; a.assign(h, vector<int>(w, 0)); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cin >> a[i][j]; } } cin >> q; int r, c, x; for (int i = 0; i < q; i++) { cin >> r >> c >> x; paint(r-1, c-1, x); } for (int i = 0; i < h; i++) { cout << a[i][0]; for (int j = 1; j < w; j++) { cout << " " << a[i][j]; } cout << endl; } return 0; }