結果

問題 No.307 最近色塗る問題多くない?
ユーザー pekempeypekempey
提出日時 2015-11-28 12:25:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 189 ms / 4,000 ms
コード長 1,367 bytes
コンパイル時間 1,305 ms
コンパイル使用メモリ 158,832 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2024-05-01 16:48:37
合計ジャッジ時間 3,670 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 5 ms
5,376 KB
testcase_08 AC 24 ms
5,760 KB
testcase_09 AC 11 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 8 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 11 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 16 ms
5,376 KB
testcase_18 AC 39 ms
5,376 KB
testcase_19 AC 34 ms
5,632 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 28 ms
5,376 KB
testcase_22 AC 26 ms
5,888 KB
testcase_23 AC 166 ms
5,888 KB
testcase_24 AC 68 ms
5,376 KB
testcase_25 AC 97 ms
5,888 KB
testcase_26 AC 182 ms
5,888 KB
testcase_27 AC 17 ms
5,376 KB
testcase_28 AC 28 ms
6,144 KB
testcase_29 AC 9 ms
5,376 KB
testcase_30 AC 189 ms
6,016 KB
testcase_31 AC 22 ms
5,376 KB
testcase_32 AC 22 ms
5,376 KB
testcase_33 AC 14 ms
5,376 KB
testcase_34 AC 22 ms
5,376 KB
testcase_35 AC 23 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:38:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   38 |                 scanf("%d%d%d", &r, &c, &x);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:47:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   47 |                         scanf("%d%d%d", &r, &c, &x);
      |                         ~~~~~^~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
#define GET_MACRO(a, b, c, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define rep2(i, a) rep3 (i, 0, a)
#define rep3(i, a, b) for (int i = (a); i < (b); i++)
#define repr(...) GET_MACRO(__VA_ARGS__, repr3, repr2)(__VA_ARGS__)
#define repr2(i, a) repr3 (i, 0, a)
#define repr3(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define chmin(a, b) ((b) < a && (a = (b), true))
#define chmax(a, b) (a < (b) && (a = (b), true))
using namespace std;
typedef long long ll;

int a[200][200], num, h, w;
int dy[] = {0, 1, 0, -1};
int dx[] = {1, 0, -1, 0};

void dfs(int y, int x, int c1, int c2) {
	if (y < 0 || y >= h || x < 0 || x >= w || a[y][x] != c1) return;
	num -= a[y][x];
	a[y][x] = c2;
	num += a[y][x];
	rep (k, 4) {
		dfs(y + dy[k], x + dx[k], c1, c2);
	}
}

int main() {
	cin >> h >> w;
	rep (i, h) rep (j, w) {
		cin >> a[i][j];
		num += a[i][j];
	}
	int q;
	cin >> q;
	while (q--) {
		int r, c, x;
		scanf("%d%d%d", &r, &c, &x);
		r--; c--;
		if (a[r][c] != x) dfs(r, c, a[r][c], x);
		if (num == 0 || num == h * w) break;
	}

	if (num == 0 || num == h * w) {
		while (q--) {
			int r, c, x;
			scanf("%d%d%d", &r, &c, &x);
			if (a[0][0] != x) {
				a[0][0] = x;
			}
		}
		rep (i, h) rep (j, w) a[i][j] = a[0][0];
	}
	rep (i, h) {
		rep (j, w) cout << a[i][j] << " ";
		cout << endl;
	}
	return 0;
}
0