結果
| 問題 |
No.307 最近色塗る問題多くない?
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-01-02 13:42:18 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 153 ms / 4,000 ms |
| コード長 | 2,415 bytes |
| コンパイル時間 | 1,778 ms |
| コンパイル使用メモリ | 179,788 KB |
| 実行使用メモリ | 6,816 KB |
| 最終ジャッジ日時 | 2024-11-21 22:20:37 |
| 合計ジャッジ時間 | 3,860 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 36 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef pair< int, int > pii;
typedef vector< pii > vp;
typedef vector< double > vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
template< class T1, class T2 >
int upmin( T1 &x, T2 v ){
if( x > v ){
x = v;
return 1;
}
return 0;
}
template< class T1, class T2 >
int upmax( T1 &x, T2 v ){
if( x < v ){
x = v;
return 1;
}
return 0;
}
const int INF = 0x3f3f3f3f;
const int MAXH = 200;
const int MAXW = 200;
int H, W;
vvi A;
int Q;
void init(){
cin >> H >> W;
A = vvi( H, vi( W ) );
for( int i = 0; i < H; ++i ){
for( int j = 0; j < W; ++j ){
cin >> A[ i ][ j ];
}
}
cin >> Q;
}
void preprocess(){
}
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };
void solve(){
vi cnt( 2 );
for( int i = 0; i < H; ++i ){
for( int j = 0; j < W; ++j ){
++cnt[ A[ i ][ j ] ];
}
}
for( int i = 0; i < Q; ++i ){
int R, C, X; cin >> R >> C >> X;
if( cnt[ 0 ] == 0 or cnt[ 1 ] == 0 ){
cnt[ X ] = max( cnt[ 0 ], cnt[ 1 ] );
cnt[ X ^ 1 ] = 0;
} else{
if( A[ R - 1 ][ C - 1 ] == X ) continue;
queue< pii > que;
A[ R - 1 ][ C - 1 ] = X;
--cnt[ X ^ 1 ];
++cnt[ X ];
que.emplace( R - 1, C - 1 );
while( not que.empty() ){
int x, y; tie( x, y ) = que.front(); que.pop();
for( int di = 0; di < 4; ++di ){
int nx = x + dx[ di ];
int ny = y + dy[ di ];
if( not ( 0 <= nx and nx < H and 0 <= ny and ny < W ) ) continue;
if( A[ nx ][ ny ] == X ) continue;
A[ nx ][ ny ] = X;
--cnt[ X ^ 1 ];
++cnt[ X ];
que.emplace( nx, ny );
}
}
}
}
if( cnt[ 0 ] == 0 ){
for( int i = 0; i < H; ++i ){
for( int j = 0; j < W; ++j ){
cout << 1 << " \n"[ j + 1 == W ];
}
}
} else if( cnt[ 1 ] == 0 ){
for( int i = 0; i < H; ++i ){
for( int j = 0; j < W; ++j ){
cout << 0 << " \n"[ j + 1 == W ];
}
}
} else{
for( int i = 0; i < H; ++i ){
for( int j = 0; j < W; ++j ){
cout << A[ i ][ j ] << " \n"[ j + 1 == W ];
}
}
}
}
signed main(){
ios::sync_with_stdio( 0 );
init();
preprocess();
solve();
return 0;
}