結果
問題 | No.307 最近色塗る問題多くない? |
ユーザー | 🐬hec |
提出日時 | 2015-11-28 00:00:49 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,348 bytes |
コンパイル時間 | 1,424 ms |
コンパイル使用メモリ | 152,020 KB |
実行使用メモリ | 8,704 KB |
最終ジャッジ日時 | 2023-10-12 00:22:17 |
合計ジャッジ時間 | 8,879 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
6,368 KB |
testcase_01 | AC | 4 ms
6,236 KB |
testcase_02 | AC | 3 ms
6,100 KB |
testcase_03 | AC | 3 ms
6,108 KB |
testcase_04 | WA | - |
testcase_05 | AC | 4 ms
6,152 KB |
testcase_06 | AC | 4 ms
6,160 KB |
testcase_07 | AC | 1,027 ms
6,404 KB |
testcase_08 | TLE | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) using namespace std; const int vmax=50010; int p[vmax]; void init(){rep(i,vmax) p[i]=i;} int find(int x){return x==p[x]?x:p[x]=find(p[x]);} void unite(int a,int b){a=find(a),b=find(b);p[b]=a;return;} bool same(int a,int b){return find(a)==find(b);} int h,w; int a[vmax]; int di[4]={1,0,-1,0},dj[4]={0,1,0,-1}; set<int> neighbor[vmax]; int main(void){ init(); scanf("%d %d",&h,&w); rep(i,h)rep(j,w) scanf("%d",a+w*i+j); rep(i,h)rep(j,w){ int idx=w*i+j; rep(k,4){ int ni=i,nj=j; ni+=di[k],nj+=dj[k]; if(ni<0||h<=ni) continue; if(nj<0||w<=nj) continue; int nidx=w*ni+nj; if(a[idx]==a[nidx]) unite(idx,nidx); } } rep(i,h)rep(j,w){ int idx=find(w*i+j); rep(k,4){ int ni=i,nj=j; ni+=di[k],nj+=dj[k]; if(ni<0||h<=ni) continue; if(nj<0||w<=nj) continue; int nidx=find(w*ni+nj); if(a[idx]!=a[nidx]) neighbor[idx].insert(nidx); } } int q; scanf("%d",&q); rep(loop,q){ int r,c,x; scanf("%d %d %d",&r,&c,&x); r--,c--; int idx=find(w*r+c); if(a[idx]==x) continue; a[idx]=x; set<int> tmp; for(auto &nidx:neighbor[idx]){ unite(idx,nidx); for(auto &j:neighbor[nidx]) tmp.insert(j); } neighbor[idx]=tmp; } rep(i,h){ rep(j,w) printf("%s%d",(j?" ":""),a[find(w*i+j)]); puts(""); } return 0; }