結果

問題 No.307 最近色塗る問題多くない?
ユーザー koyumeishikoyumeishi
提出日時 2015-11-27 06:06:16
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,212 bytes
コンパイル時間 456 ms
コンパイル使用メモリ 63,224 KB
実行使用メモリ 9,944 KB
最終ジャッジ日時 2023-10-11 23:10:10
合計ジャッジ時間 7,466 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 414 ms
4,348 KB
testcase_08 TLE -
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 <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