結果

問題 No.307 最近色塗る問題多くない?
ユーザー koyumeishikoyumeishi
提出日時 2015-11-27 06:05:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 147 ms / 4,000 ms
コード長 1,210 bytes
コンパイル時間 766 ms
コンパイル使用メモリ 62,660 KB
実行使用メモリ 7,552 KB
最終ジャッジ日時 2024-05-01 16:32:05
合計ジャッジ時間 3,052 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 5 ms
5,376 KB
testcase_08 AC 20 ms
6,784 KB
testcase_09 AC 9 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 7 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 10 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 11 ms
5,376 KB
testcase_18 AC 27 ms
5,504 KB
testcase_19 AC 24 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 20 ms
5,376 KB
testcase_22 AC 20 ms
6,912 KB
testcase_23 AC 127 ms
7,296 KB
testcase_24 AC 49 ms
6,016 KB
testcase_25 AC 75 ms
7,296 KB
testcase_26 AC 144 ms
7,424 KB
testcase_27 AC 14 ms
5,376 KB
testcase_28 AC 24 ms
7,424 KB
testcase_29 AC 8 ms
5,376 KB
testcase_30 AC 147 ms
7,424 KB
testcase_31 AC 20 ms
5,376 KB
testcase_32 AC 20 ms
5,376 KB
testcase_33 AC 13 ms
7,552 KB
testcase_34 AC 20 ms
5,376 KB
testcase_35 AC 22 ms
5,632 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main_()’:
main.cpp:30:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   30 |         scanf("%d%d", &h,&w);
      |         ~~~~~^~~~~~~~~~~~~~~
main.cpp:34:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   34 |                         scanf("%d", &a[i][j]);
      |                         ~~~~~^~~~~~~~~~~~~~~~
main.cpp:42:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   42 |         scanf("%d", &q);
      |         ~~~~~^~~~~~~~~~
main.cpp:45:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   45 |                 scanf("%d%d%d", &r,&c,&x);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~

ソースコード

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