結果

問題 No.307 最近色塗る問題多くない?
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-10-07 22:25:18
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 949 bytes
コンパイル時間 858 ms
コンパイル使用メモリ 67,436 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-01 15:04:52
合計ジャッジ時間 3,926 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 WA -
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 5 ms
6,948 KB
testcase_11 AC 10 ms
6,940 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 55 ms
6,940 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2 ms
6,940 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 23 ms
6,940 KB
testcase_28 WA -
testcase_29 AC 28 ms
6,940 KB
testcase_30 WA -
testcase_31 AC 40 ms
6,944 KB
testcase_32 AC 40 ms
6,944 KB
testcase_33 WA -
testcase_34 AC 39 ms
6,944 KB
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <queue>
#include <cstdio>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};	
int h, w;
int a[210][210];
int q;

int main(void){
	cin >> h >> w;
	rep(i, h)rep(j, w) cin >> a[i][j];

	cin >> q;
	rep(i, q){
		int r, c, x; cin >> r >> c >> x;
		r--;c--;
		queue<pair<int, int> > que;
		que.push(make_pair(r, c));
		int color = a[r][c];
		if(color == x) continue;
		a[r][c] = x;
		int cnt = 0;
		while(!que.empty() && cnt < 1000){
			cnt++;
			int nowy = que.front().first, nowx = que.front().second;
			que.pop();
			rep(k, 4){
				int ny = nowy + dy[k], nx = nowx + dx[k];
				if(!(0 <= ny && ny < h && 0 <= nx && nx < w)) continue;
				if(a[ny][nx] == color){
					a[ny][nx] = x;
					que.push(make_pair(ny, nx));
				}
			}
		}
	}
	rep(i, h){
		rep(j, w){
			printf("%d ", a[i][j]);
		}
		printf("\n");
	}
	return 0;
}
0