結果

問題 No.307 最近色塗る問題多くない?
ユーザー masamasa
提出日時 2015-12-02 18:14:10
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,287 bytes
コンパイル時間 865 ms
コンパイル使用メモリ 75,368 KB
実行使用メモリ 814,660 KB
最終ジャッジ日時 2023-10-12 09:02:09
合計ジャッジ時間 5,804 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 1 ms
4,368 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 MLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
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 <cstdio>
#include <vector>
#include <utility>
#include <queue>

using namespace std;

const int dr[4] = {1, 0, -1, 0};
const int dc[4] = {0, 1, 0, -1};

int h, w, q;
vector< vector<int> > a;

void paint(int r, int c, int x) {
	vector< vector<bool> > painted(h, vector<bool>(w, false));

	int base_color = a[r][c];
	if (base_color == x) {
		return;
	}

	queue<pair<int, int> > que;
	que.push(make_pair(r, c));


	while (!que.empty()) {
		auto pos = que.front();
		que.pop();

		a[pos.first][pos.second] = x;
		painted[pos.first][pos.second] = true;

		for (int i = 0; i < 4; i++) {
			int nr = pos.first + dr[i];
			int nc = pos.second + dc[i];

			if (nr < 0 || h <= nr || nc < 0 || w <= nc) {
				continue;
			}
			if (painted[nr][nc]) {
				continue;
			}
			if (a[nr][nc] != base_color) {
				continue;
			}

			que.push(make_pair(nr, nc));
		}
	}
}

int main() {

	cin >> h >> w;
	a.assign(h, vector<int>(w, 0));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a[i][j];
		}
	}
	cin >> q;
	int r, c, x;

	for (int i = 0; i < q; i++) {
		cin >> r >> c >> x;
		paint(r-1, c-1, x);
	}


	for (int i = 0; i < h; i++) {
		cout << a[i][0];
		for (int j = 1; j < w; j++) {
			cout << " " << a[i][j];
		}
		cout << endl;
	}

	return 0;
}
0