結果
問題 | No.307 最近色塗る問題多くない? |
ユーザー |
![]() |
提出日時 | 2016-06-19 22:01:32 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 138 ms / 4,000 ms |
コード長 | 1,495 bytes |
コンパイル時間 | 595 ms |
コンパイル使用メモリ | 71,760 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-21 22:17:20 |
合計ジャッジ時間 | 2,708 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 36 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:20:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 20 | scanf("%d%d",&H,&W); | ~~~~~^~~~~~~~~~~~~~ main.cpp:21:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 21 | rep (i,H) rep (j,W) scanf("%d",&A[i][j]); | ~~~~~^~~~~~~~~~~~~~~ main.cpp:24:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 24 | scanf("%d",&Q); | ~~~~~^~~~~~~~~ main.cpp:29:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 29 | scanf("%d%d%d",&R,&C,&X); | ~~~~~^~~~~~~~~~~~~~~~~~~
ソースコード
#include <iostream> #include <vector> #include <map> #include <algorithm> #include <queue> using namespace std; #define REP(i,s,e) for (i = s; i <= e; i++) #define rep(i,n) REP (i,0,(int)(n)-1) #define RREP(i,s,e) for (i = s; i >= e; i--) #define rrep(i,n) RREP (i,(int)(n)-1,0) #define INF (int)1e8 #define MOD (int)(1e9+7) typedef long long ll; int main(void) { int i, j, H, W; int A[200][200]; scanf("%d%d",&H,&W); rep (i,H) rep (j,W) scanf("%d",&A[i][j]); int Q; scanf("%d",&Q); bool same = false; int X; while (Q--) { int R, C; scanf("%d%d%d",&R,&C,&X); R--; C--; if (same) continue; if (A[R][C] == X) continue; A[R][C] = X; queue<pair<int,int>> q; q.push(make_pair(R,C)); int dxy[] = {1,0,-1,0}; int cnt = 0; while (!q.empty()) { int y = q.front().first; int x = q.front().second; q.pop(); rep (i,4) { int ny = y + dxy[i]; int nx = x + dxy[(i+1)%4]; if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue; if (A[ny][nx] != X) { q.push(make_pair(ny,nx)); A[ny][nx] = X; } } cnt++; } if (cnt == H * W) same = true; } rep (i,H) { rep (j,W) printf("%d ",same ? X : A[i][j]); printf("\n"); } return 0; }