結果

問題 No.307 最近色塗る問題多くない?
ユーザー vain0vain0
提出日時 2015-11-28 02:11:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 354 ms / 4,000 ms
コード長 1,952 bytes
コンパイル時間 1,136 ms
コンパイル使用メモリ 110,196 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-14 03:56:09
合計ジャッジ時間 4,397 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 7 ms
4,380 KB
testcase_08 AC 32 ms
4,376 KB
testcase_09 AC 12 ms
4,380 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 10 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 21 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 21 ms
4,380 KB
testcase_18 AC 59 ms
4,376 KB
testcase_19 AC 50 ms
4,380 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 40 ms
4,380 KB
testcase_22 AC 35 ms
4,376 KB
testcase_23 AC 310 ms
4,380 KB
testcase_24 AC 117 ms
4,376 KB
testcase_25 AC 175 ms
4,376 KB
testcase_26 AC 345 ms
4,380 KB
testcase_27 AC 44 ms
4,384 KB
testcase_28 AC 51 ms
4,376 KB
testcase_29 AC 15 ms
4,376 KB
testcase_30 AC 354 ms
4,376 KB
testcase_31 AC 60 ms
4,380 KB
testcase_32 AC 36 ms
4,376 KB
testcase_33 AC 11 ms
4,376 KB
testcase_34 AC 34 ms
4,380 KB
testcase_35 AC 34 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <functional>
#include <cmath>
#ifndef ONLINE_JUDGE
# include <complex>
# include <random>
# include <array>
# include <unordered_map>
# define mkt make_tuple
#endif
#ifdef _LOCAL
# include "local/local.hpp"
#else
# define assert(...) ((void)0)
# define ifdebug if (false)
# define echo(...) ((void)0)
#endif
using namespace std;
typedef long long ll; typedef unsigned long long ull;
#define repi(_I, _B, _E) for(int _I = (_B); (_I) < (_E); ++ (_I))
#define rep(_I, _N) for(int _I = 0; (_I) < (_N); ++ (_I))
#define all(_X) (_X).begin(), (_X).end()

static int dx[] = { 1, 0, -1, 0 }, dy[] = { 0, 1, 0, -1 };

vector<vector<bool>> board, done;

int h, w;
int cnt_false;

void bfs(int i0, int j0, bool b)
{
	queue<pair<int, int>> que;
	que.push({ i0, j0 });

	int i, j;
	while ( ! que.empty() ) {
		tie(i, j) = que.front();
		que.pop();
		if ( 0 <= i && i < h && 0 <= j && j < w
			&& board[i][j] != b
			&& (! done[i][j])
			) {

			done[i][j] = true;
			board[i][j] = b;
			cnt_false += (b ? -1 : 1);
			rep(d, 4)
			{
				que.push({ i + dy[d], j + dx[d] });
			}
		}
	}
}

bool completed()
{
	return cnt_false == 0 || cnt_false == h*w;
}

int main()
{
	cin >> h >> w;

	board.resize(h, vector<bool>(w));
	done.resize(h, vector<bool>(w));

	rep(i, h) rep(j, w)
	{
		int a;
		cin >> a;
		board[i][j] = (a != 0);
		if ( a == 0 ) cnt_false ++;
	}

	int q;
	cin >> q;
	rep(k, q)
	{
		int r, c, a;
		cin >> r >> c >> a;
		r--; c--;
		bool b = (a != 0);

		if ( completed() ) {
			board[0][0] = b;
		} else {
			if ( board[r][c] != b ) {
				bfs(r, c, b);
				rep(i, h) fill(all(done[i]), false);
			}
		}
	}

	rep(i, h)
	{
		rep(j, w)
		{
			if ( j != 0 ) cout << ' ';
			cout << ((completed() ? board[0][0] : board[i][j]) ? 1 : 0);
		}
		cout << endl;
	}
	return 0;
}
0