結果

問題 No.307 最近色塗る問題多くない?
ユーザー FF256grhy
提出日時 2015-11-28 02:11:12
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 939 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 23,552 KB
実行使用メモリ 14,008 KB
最終ジャッジ日時 2024-09-14 01:51:30
合計ジャッジ時間 6,271 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 8 TLE * 1 -- * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:8:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |         scanf("%d %d", &h, &w);
      |         ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:12:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |                 scanf("%d", &a[i][j]);
      |                 ~~~~~^~~~~~~~~~~~~~~~
main.cpp:16:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |         scanf("%d", &q);
      |         ~~~~~^~~~~~~~~~
main.cpp:19:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   19 |                 scanf("%d %d %d", &r, &c, &x);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

int h, w, a[202][202], q;

void paint(int, int, int);

int main(void) {
	scanf("%d %d", &h, &w);
	int i, j;
	for(i = 1; i <= h; i++) {
	for(j = 1; j <= w; j++) {
		scanf("%d", &a[i][j]);
	}
	}
	
	scanf("%d", &q);
	for(i = 0; i < q; i++) {
		int r, c, x;
		scanf("%d %d %d", &r, &c, &x);
		paint(r, c, x);
		
		/*
		int k;
		for(k = 1; k <= h; k++) {
		for(j = 1; j <= w; j++) {
		printf("%s%d", (j == 1 ? "" : " "), a[k][j] % 2);
		} printf("\n");
		}
		printf("\n\n");*/
	}
	
	for(i = 1; i <= h; i++) {
	for(j = 1; j <= w; j++) {
		printf("%s%d", (j == 1 ? "" : " "), a[i][j] % 2);
	} printf("\n");
	}
	
	return 0;
}

void paint(int r, int c, int x) {
	if(r == 0 || r == h + 1 || c == 0 || c == w + 1) { return; }
	if(a[r][c] == x) { return; }
	a[r][c] = (a[r][c] + 1) % 2;
	int dr[4] = {  0, 1, 0, -1 };
	int dc[4] = { -1, 0, 1,  0 };
	int i;
	for(i = 0; i < 4; i++) {
		paint(r + dr[i], c + dc[i], x);
	}
	return;
}
0