結果
問題 | No.307 最近色塗る問題多くない? |
ユーザー |
![]() |
提出日時 | 2015-11-27 23:38:31 |
言語 | C++11 (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,607 bytes |
コンパイル時間 | 692 ms |
コンパイル使用メモリ | 70,624 KB |
実行使用メモリ | 7,424 KB |
最終ジャッジ日時 | 2024-09-14 00:58:14 |
合計ジャッジ時間 | 4,867 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 WA * 22 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:64:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 64 | scanf("%d%d",&h,&w); | ~~~~~^~~~~~~~~~~~~~ main.cpp:67:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 67 | scanf("%d",&dat[y][x]); | ~~~~~^~~~~~~~~~~~~~~~~ main.cpp:109:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 109 | scanf("%d",&qqq); | ~~~~~^~~~~~~~~~~ main.cpp:112:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 112 | scanf("%d%d%d",&y,&x,&c); | ~~~~~^~~~~~~~~~~~~~~~~~~
ソースコード
#include<cstdio> #include<cstring> #include<vector> #include<queue> #include<algorithm> #include<cmath> #include<climits> #include<string> #include<set> #include<map> using namespace std; #define rep(i,n) for(int i=0;i<((int)(n));i++) #define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++) #define irep(i,n) for(int i=((int)(n))-1;i>=0;i--) #define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--) typedef long long int lli; typedef pair<int,int> mp; #define fir first #define sec second #define IINF INT_MAX #define LINF LLONG_MAX int h,w; int dat[205][205]; int gone[205][205]; int dd[5]={1,0,-1,0,1}; vector<mp> vs[205][205]; mp uni[205][205]; void init(){ rep(y,205){ rep(x,205){ uni[y][x]=mp(y,x); } } } mp find(mp p){ mp& np=uni[p.fir][p.sec]; if(np==p)return p; return (np=find(np)); } void mer(mp pa,mp pb){ mp pp=find(pb); uni[pp.fir][pp.sec]=find(pa); } bool same(mp pa,mp pb){ return find(pa)==find(pb); } int main(void){ init(); scanf("%d%d",&h,&w); reg(y,1,h){ reg(x,1,w){ scanf("%d",&dat[y][x]); } } reg(y,1,h){ reg(x,1,w-1){ if(dat[y][x]==dat[y][x+1])mer(mp(y,x),mp(y,x+1)); } } reg(y,1,h-1){ reg(x,1,w){ if(dat[y][x]==dat[y+1][x])mer(mp(y+1,x),mp(y,x)); } } reg(y,1,h){ reg(x,1,w-1){ if(dat[y][x]!=dat[y][x+1]){ mp pa=find(mp(y,x)); mp pb=find(mp(y,x+1)); //printf("(%d %d) (%d %d)\n",pa.fir,pa.sec,pb.fir,pb.sec); vs[pa.fir][pa.sec].push_back(pb); vs[pb.fir][pb.sec].push_back(pa); } } } //printf("yo\n"); reg(y,1,h-1){ reg(x,1,w){ if(dat[y][x]!=dat[y+1][x]){ mp pa=find(mp(y,x)); mp pb=find(mp(y+1,x)); //printf("(%d %d) (%d %d)\n",pa.fir,pa.sec,pb.fir,pb.sec); vs[pa.fir][pa.sec].push_back(pb); vs[pb.fir][pb.sec].push_back(pa); } } } int qqq; scanf("%d",&qqq); rep(i,qqq){ int y,x,c; scanf("%d%d%d",&y,&x,&c); memset(gone,0,sizeof(gone)); mp np=find(mp(y,x)); if(dat[np.fir][np.sec]==c)continue; dat[np.fir][np.sec]=c; vector<mp> tvs; for(mp pa :vs[y][x]){ //printf("rin %d %d\n",pa.fir,pa.sec); if(!same(np,pa)){ mer(np,pa); /* reg(y,1,h){ reg(x,1,w){ mp pp=find(mp(y,x)); printf("%d%c",dat[pp.fir][pp.sec],x==w?'\n':' '); } } */ for(mp pb :vs[pa.fir][pa.sec]){ if(!same(np,pb))tvs.push_back(np); } } } swap(vs[y][x],tvs); /* reg(y,1,h){ reg(x,1,w){ mp pp=find(mp(y,x)); printf("%d%c",dat[pp.fir][pp.sec],x==w?'\n':' '); } }*/ } reg(y,1,h){ reg(x,1,w){ mp pp=find(mp(y,x)); printf("%d%c",dat[pp.fir][pp.sec],x==w?'\n':' '); } } return 0; }