結果
問題 | No.307 最近色塗る問題多くない? |
ユーザー |
![]() |
提出日時 | 2017-01-14 03:37:52 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,130 bytes |
コンパイル時間 | 1,296 ms |
コンパイル使用メモリ | 100,528 KB |
実行使用メモリ | 10,656 KB |
最終ジャッジ日時 | 2024-12-21 12:38:27 |
合計ジャッジ時間 | 24,275 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 WA * 1 TLE * 2 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:126:37: warning: 'col' may be used uninitialized [-Wmaybe-uninitialized] 126 | rep(i, h) rep(j, w) f[i][j] = col; | ~~~~~~~~^~~~~ main.cpp:91:9: note: 'col' was declared here 91 | int col; | ^~~
ソースコード
#include "math.h" #include <algorithm> #include <bitset> #include <complex> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> #define ifor(i, a, b) for (int i = (a); i < (b); i++) #define rfor(i, a, b) for (int i = (b)-1; i >= (a); i--) #define rep(i, n) for (int i = 0; i < (n); i++) #define rrep(i, n) for (int i = (n)-1; i >= 0; i--) using namespace std; typedef long double ld; typedef long long int lli; typedef complex<double> P; const double eps = 1e-11; int vx[4] = {1, 0, -1, 0}; int vy[4] = {0, 1, 0, -1}; typedef vector<double> Vec; typedef vector<int> vec; typedef vector<Vec> MAT; typedef vector<vec> mat; lli MOD = 1000000007; int h, w; bool inrange(int x, int y) { return 0 <= x && x < h && y < w && 0 <= y; } int f[205][205]; bool used[300][300]; int temp[300][300]; void paint(int x, int y, int from, int c) { queue<pair<int, int>> que; que.push(make_pair(x, y)); while (!que.empty()) { pair<int, int> cur = que.front(); x = cur.first; y = cur.second; temp[x][y] = c; used[x][y] = true; que.pop(); rep(i, 4) { int nx = vx[i] + x; int ny = vy[i] + y; if (inrange(nx, ny)) { if (f[nx][ny] == from && !used[nx][ny]) { temp[nx][ny] = c; used[nx][ny] = true; que.push(make_pair(nx, ny)); } } } } } inline void dfs(int x, int y, int from, int c) { temp[x][y] = c; used[x][y] = true; rep(i, 4) { int nx = vx[i] + x; int ny = vy[i] + y; if (inrange(nx, ny)) { if (f[nx][ny] == from && !used[nx][ny]) { temp[nx][ny] = c; used[nx][ny] = true; dfs(nx, ny, from, c); } } } }; int main() { ios::sync_with_stdio(false); cin >> h >> w; int a, b, c; rep(i, h) rep(j, w) cin >> f[i][j]; int q; cin >> q; bool mono = false; bool update; int col; rep(m, q) { cin >> a >> b >> c; a--, b--; if (!mono) { int color = f[0][0]; update = false; rep(i, h) rep(j, w) { used[i][j] = false; temp[i][j] = f[i][j]; if (f[0][0] != f[i][j]) update = true; } if (!update) { mono = true; } paint(a, b, f[a][b], c); rep(i, h) rep(j, w) f[i][j] = temp[i][j]; } else { col = c; } // rep(i, h) rep(j, w) // { // cout << f[i][j]; // if (j == w - 1) // cout << endl; // else // cout << ' '; // } // cout << endl; } if (mono) rep(i, h) rep(j, w) f[i][j] = col; rep(i, h) rep(j, w) { cout << f[i][j]; if (j == w - 1) cout << '\n'; else cout << ' '; } }