結果

問題 No.307 最近色塗る問題多くない?
ユーザー mokomoko
提出日時 2018-03-19 09:16:38
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,509 bytes
コンパイル時間 2,551 ms
コンパイル使用メモリ 149,128 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-08-30 03:33:35
合計ジャッジ時間 15,730 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,760 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 29 ms
4,376 KB
testcase_09 AC 9 ms
4,380 KB
testcase_10 AC 291 ms
4,380 KB
testcase_11 AC 1,706 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 11 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 11 ms
4,380 KB
testcase_18 AC 29 ms
4,380 KB
testcase_19 AC 25 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 31 ms
4,376 KB
testcase_22 AC 23 ms
4,376 KB
testcase_23 AC 136 ms
4,380 KB
testcase_24 AC 58 ms
4,376 KB
testcase_25 AC 85 ms
4,376 KB
testcase_26 AC 156 ms
4,376 KB
testcase_27 AC 351 ms
4,376 KB
testcase_28 AC 362 ms
4,380 KB
testcase_29 AC 7 ms
4,380 KB
testcase_30 AC 1,012 ms
4,376 KB
testcase_31 AC 874 ms
4,380 KB
testcase_32 AC 875 ms
4,380 KB
testcase_33 AC 8 ms
4,376 KB
testcase_34 TLE -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,P> PP;

//-----------------------------------------------------------------------------

int h,w,fld[200][200],r,c,x,q;

int bfs(int sx,int sy,int color,int dir) {
	int cnt=1;
	bool used[200][200];
	REP(i,200) REP(j,200) used[i][j]=false;
	using P=pair<int,int>;
	queue<P> Q;

	int S=fld[sy][sx];
	fld[sy][sx]=color;
	used[sy][sx]=true;
	Q.emplace(sx,sy);

	int dx[]={ 0, 0, 1,-1, 1,-1, 1,-1};
	int dy[]={ 1,-1, 0, 0, 1, 1,-1,-1};

	while(!Q.empty()) {
		P p=Q.front();Q.pop();
		for(int i=0;i<dir;i++) {
			int nx=p.first+dx[i],ny=p.second+dy[i];
			if(nx<0||nx>=w||ny<0||ny>=h) continue;
			if(fld[ny][nx]!=S) continue;
			if(used[ny][nx]) continue;
			used[ny][nx]=true;
			fld[ny][nx]=color;
			cnt++;
			Q.emplace(nx,ny);
		}
	}
	return cnt;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin>>h>>w;
	REP(i,h) REP(j,w) cin>>fld[i][j];
	cin>>q;
	bool ok=false;
	while(q--) {
		cin>>r>>c>>x;
		if(ok) {
			if(q==0) {
				REP(i,h) REP(j,w) fld[i][j]=x;
			}
		}
		else {
			if(bfs(c-1,r-1,x,4)==h*w) ok=true;
		}
	}
	REP(i,h) {
		REP(j,w) cout<<fld[i][j]<<' ';
		cout<<endl;
	}

	return 0;
}
0