結果

問題 No.307 最近色塗る問題多くない?
ユーザー vain0vain0
提出日時 2015-11-27 23:32:27
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,554 bytes
コンパイル時間 943 ms
コンパイル使用メモリ 85,736 KB
実行使用メモリ 8,744 KB
最終ジャッジ日時 2023-10-12 00:56:05
合計ジャッジ時間 7,099 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 535 ms
4,352 KB
testcase_08 TLE -
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 <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 "module/for_local.h"
#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;

void dfs(int i, int j, bool b)
{
	if ( 0 <= i && i < h && 0 <= j && j < w
		&& board[i][j] != b
		&& ! done[i][j]
		) {
		done[i][j] = true;
		board[i][j] = b;
		rep(d, 4)
		{
			dfs(i + dy[d], j + dx[d], b);
		}
	}
}

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);
	}

	int q;
	cin >> q;
	rep(k, q)
	{
		int r, c, a;
		cin >> r >> c >> a;
		r--; c--;

		if ( board[r][c] != a ) {
			dfs(r, c, a != 0);
			rep(i, h) rep(j, w) done[i][j] = false;
		}
	}

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