結果
問題 | No.307 最近色塗る問題多くない? |
ユーザー |
|
提出日時 | 2016-10-02 06:26:39 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 134 ms / 4,000 ms |
コード長 | 1,662 bytes |
コンパイル時間 | 1,794 ms |
コンパイル使用メモリ | 171,808 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-21 22:18:25 |
合計ジャッジ時間 | 3,636 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 36 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef long long ll;#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)#define all(x) (x).begin(),(x).end()#define pb push_back#define fi first#define se secondtypedef pair<int,int> pi;int main(){int h,w;int a[200][200];scanf(" %d %d", &h, &w);rep(i,h)rep(j,w) scanf(" %d", &a[i][j]);#define IN(x,y) (0<=x && x<w && 0<=y && y<h)int dx[4]={1,-1,0,0}, dy[4]={0,0,1,-1};// クエリ処理bool all_done=false;int col=-1;int Q;scanf(" %d", &Q);while(Q--){int r,c,x;scanf(" %d %d %d", &r, &c, &x);--r;--c;if(all_done){col=x;continue;}if(a[r][c]==x) continue;queue<pi> que;que.push(pi(r,c));int vis_num=1;a[r][c]=x;while(!que.empty()){pi now=que.front();que.pop();rep(i,4){int nx=now.se+dx[i], ny=now.fi+dy[i];if(IN(nx,ny) && a[ny][nx]!=x){a[ny][nx]=x;que.push(pi(ny,nx));++vis_num;}}}if(vis_num==h*w){all_done=true;col=x;}}// 出力rep(y,h){rep(x,w){if(x) printf(" ");if(all_done) a[y][x]=col;printf("%d", a[y][x]);}printf("\n");}return 0;}