結果

問題 No.307 最近色塗る問題多くない?
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-10-07 20:09:42
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 877 bytes
コンパイル時間 582 ms
コンパイル使用メモリ 67,308 KB
実行使用メモリ 814,352 KB
最終ジャッジ日時 2024-05-01 15:02:50
合計ジャッジ時間 4,065 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 MLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
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];
		a[r][c] = x;
		while(!que.empty()){
			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 < 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