結果
| 問題 | No.307 最近色塗る問題多くない? |
| コンテスト | |
| ユーザー |
vain0
|
| 提出日時 | 2015-11-28 02:01:27 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,787 bytes |
| 記録 | |
| コンパイル時間 | 931 ms |
| コンパイル使用メモリ | 89,736 KB |
| 実行使用メモリ | 13,888 KB |
| 最終ジャッジ日時 | 2024-09-14 01:49:50 |
| 合計ジャッジ時間 | 6,933 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 8 TLE * 1 -- * 27 |
ソースコード
#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 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;
cnt_false += (b ? 1 : -1);
rep(d, 4)
{
dfs(i + dy[d], j + dx[d], b);
}
}
}
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--;
if ( completed() ) {
board[0][0] = (a != 0);
} else {
if ( board[r][c] != a ) {
dfs(r, c, a != 0);
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;
}
vain0