結果
| 問題 |
No.307 最近色塗る問題多くない?
|
| コンテスト | |
| ユーザー |
IL_msta
|
| 提出日時 | 2015-11-28 14:00:02 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,123 bytes |
| コンパイル時間 | 1,072 ms |
| コンパイル使用メモリ | 103,408 KB |
| 実行使用メモリ | 8,320 KB |
| 最終ジャッジ日時 | 2024-09-14 04:50:03 |
| 合計ジャッジ時間 | 7,094 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 8 TLE * 1 -- * 27 |
ソースコード
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <vector>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>
#include <valarray>
#include<cassert>//assert();
//#include <random>//xAOJ
/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
#define PII pair<int,int>
/////////
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
/////////
using namespace::std;
/////////
/////////
void solve(){
int H,W;
cin >> H >> W;
vector< vector<bool> > masu(H,vector<bool>(W) );
int temp;
for(int h=0;h<H;++h){
for(int w=0;w<W;++w){
cin >> temp;
if( temp == 0 ){
masu[h][w] = false;
}else{
masu[h][w] = true;
}
}
}
////////////////
int Q;
cin >> Q;
pair<int,int> qtemp,inqueue;
int X;
bool bX;
queue< pair<int,int> > q;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1, 0,-1};
int k;
while(Q--){
cin >> qtemp.first >> qtemp.second >> X;
--qtemp.first;
--qtemp.second;
bX = X==0?false:true;
if( masu[qtemp.first][qtemp.second] == bX )continue;
masu[qtemp.first][qtemp.second] = bX;
q.push( qtemp );
while( !q.empty() ){
qtemp = q.front();
q.pop();
//masu[btemp.first][btemp.second] = X;//X以外の連結をXに塗る
for(k=0;k<4;++k){
inqueue.first = qtemp.first + dx[k];
inqueue.second = qtemp.second + dy[k];
if( 0 <= inqueue.first && inqueue.first < H &&
0 <= inqueue.second && inqueue.second < W ){
if( masu[inqueue.first][inqueue.second] != bX ){
masu[inqueue.first][inqueue.second] = bX;
q.push( inqueue );
}
}
}
}
}
for(int h=0;h<H;++h){
for(int w = 0;w<W;++w){
if( w != 0 ){
cout << ' ';
}
if( masu[h][w] ){
cout << 1;
}else{
cout << 0;
}
}
cout << endl;
}
}
int main(void){
std::cin.tie(0);
std::ios::sync_with_stdio(false);
std::cout << std::fixed;//
cout << setprecision(16);//
//cpp
solve();
return 0;
}
IL_msta