結果

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

テストケース

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

ソースコード

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 < h * w){
			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