結果

問題 No.307 最近色塗る問題多くない?
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-10-07 20:09:42
言語 C++11
(gcc 13.3.0)
結果
MLE  
実行時間 -
コード長 877 bytes
コンパイル時間 616 ms
コンパイル使用メモリ 68,340 KB
実行使用メモリ 821,688 KB
最終ジャッジ日時 2024-11-21 19:54:39
合計ジャッジ時間 41,850 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 2 RE * 22 TLE * 1 MLE * 11
権限があれば一括ダウンロードができます

ソースコード

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