結果

問題 No.307 最近色塗る問題多くない?
ユーザー koyumeishikoyumeishi
提出日時 2015-11-27 06:05:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 176 ms / 4,000 ms
コード長 1,210 bytes
コンパイル時間 1,279 ms
コンパイル使用メモリ 62,564 KB
実行使用メモリ 6,216 KB
最終ジャッジ日時 2023-08-14 03:42:17
合計ジャッジ時間 3,232 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 20 ms
5,792 KB
testcase_09 AC 9 ms
4,612 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 6 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 10 ms
4,376 KB
testcase_14 AC 3 ms
4,384 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 12 ms
4,488 KB
testcase_18 AC 30 ms
4,716 KB
testcase_19 AC 26 ms
4,736 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 22 ms
4,488 KB
testcase_22 AC 21 ms
5,732 KB
testcase_23 AC 151 ms
6,024 KB
testcase_24 AC 58 ms
5,084 KB
testcase_25 AC 87 ms
6,048 KB
testcase_26 AC 170 ms
6,096 KB
testcase_27 AC 13 ms
4,380 KB
testcase_28 AC 24 ms
5,936 KB
testcase_29 AC 7 ms
4,380 KB
testcase_30 AC 176 ms
6,196 KB
testcase_31 AC 18 ms
4,384 KB
testcase_32 AC 18 ms
4,376 KB
testcase_33 AC 12 ms
6,216 KB
testcase_34 AC 18 ms
4,380 KB
testcase_35 AC 20 ms
4,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <ctime>
using namespace std;

int dx[] = {0,0,1,-1,0,0};
int* dy = dx+2;

int h,w;

int dfs(vector<vector<int>>& a, int r, int c, int col){
	if(a[r][c] == col) return 0;

	a[r][c] = col;
	int ret = 1;

	for(int k__=0; k__<4; k__++){
		int new_x = c + dx[k__];
		int new_y = r + dy[k__];
		if(new_x < 0 || new_x >= w || new_y < 0 || new_y >= h) continue;
		if(a[new_y][new_x] == col) continue;
		ret += dfs(a, new_y, new_x, col);	
	}

	return ret;
}

int main_(){
	scanf("%d%d", &h,&w);
	vector<vector<int>> a(h, vector<int>(w));
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			scanf("%d", &a[i][j]);
		}
	}

	bool filled = false;
	int last = -1;

	int q;
	scanf("%d", &q);
	while(q--){
		int r,c,x;
		scanf("%d%d%d", &r,&c,&x);
		r--; c--;

		last = x;
		if(filled) continue;

		int cnt = dfs(a,r,c, x);
		filled = cnt == h*w;
	}

	if(filled){
		for(int i=0; i<h; i++){
			fill(a[i].begin(), a[i].end(), last);
		}
	}
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			printf("%d%s", a[i][j], (j==w-1)?"\n":" ");
		}
	}
	return 0;
}

int main(){
	auto start = clock();
	main_();
	cerr << clock() - start << " [ms]" << endl;
	return 0;
}
0