結果

問題 No.307 最近色塗る問題多くない?
ユーザー IL_mstaIL_msta
提出日時 2015-11-28 14:00:02
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,123 bytes
コンパイル時間 1,074 ms
コンパイル使用メモリ 102,444 KB
実行使用メモリ 8,696 KB
最終ジャッジ日時 2023-10-12 05:21:25
合計ジャッジ時間 13,606 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 229 ms
4,348 KB
testcase_08 TLE -
testcase_09 AC 418 ms
4,348 KB
testcase_10 AC 3 ms
4,352 KB
testcase_11 AC 6 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 37 ms
4,348 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 10 ms
4,348 KB
testcase_18 AC 24 ms
4,352 KB
testcase_19 AC 21 ms
4,348 KB
testcase_20 AC 2 ms
4,352 KB
testcase_21 AC 17 ms
4,348 KB
testcase_22 AC 15 ms
4,352 KB
testcase_23 AC 109 ms
4,352 KB
testcase_24 AC 43 ms
4,348 KB
testcase_25 TLE -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0