結果
問題 | No.307 最近色塗る問題多くない? |
ユーザー |
![]() |
提出日時 | 2015-11-27 22:45:40 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 369 ms / 4,000 ms |
コード長 | 2,695 bytes |
コンパイル時間 | 683 ms |
コンパイル使用メモリ | 82,528 KB |
実行使用メモリ | 7,040 KB |
最終ジャッジ日時 | 2024-11-21 21:48:03 |
合計ジャッジ時間 | 3,628 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 36 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:90:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 90 | scanf("%d%d",&h,&w); | ~~~~~^~~~~~~~~~~~~~ main.cpp:91:25: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 91 | rep(i,h)rep(j,w) scanf("%d",&a[i][j]); | ~~~~~^~~~~~~~~~~~~~~ main.cpp:93:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 93 | scanf("%d",&q); | ~~~~~^~~~~~~~~ main.cpp:99:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 99 | scanf("%d%d%d",&r,&c,&x); | ~~~~~^~~~~~~~~~~~~~~~~~~
ソースコード
#include <cstdio> #include <algorithm> #include <stack> #include <queue> #include <deque> #include <vector> #include <string> #include <string.h> #include <cstdlib> #include <ctime> #include <cmath> #include <map> #include <set> #include <iostream> #include <sstream> #include <numeric> #include <cctype> #define fi first #define se second #define rep(i,n) for(int i = 0; i < n; ++i) #define rrep(i,n) for(int i = 1; i <= n; ++i) #define drep(i,n) for(int i = n-1; i >= 0; --i) #define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next) #define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++) #define rng(a) a.begin(),a.end() #define maxs(x,y) x = max(x,y) #define mins(x,y) x = min(x,y) #define pb push_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcount #define snuke srand((unsigned)clock()+(unsigned)time(NULL)); #define df(x) int x = in() using namespace std; typedef long long int ll; typedef pair<int,int> P; typedef vector<int> vi; typedef vector<vi> vvi; inline int in() { int x; scanf("%d",&x); return x;} inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');} const int MX = 205, INF = 1000010000; const ll LINF = 1000000000000000000ll; const double eps = 1e-10; // Union find struct uf { vector<int> d; uf(){} uf(int mx):d(mx,-1){} int root(int x){ if(d[x] < 0) return x; return d[x] = root(d[x]); } void unite(int x, int y){ x = root(x); y = root(y); if(x == y) return; d[y] = x; } }; // int h, w; int a[MX][MX]; const int di[] = {-1,0,1,0}, dj[] = {0,-1,0,1}; //^<v> //const int di[] = {-1,0,1,-1,1,-1,0,1}, dj[] = {-1,-1,-1,0,0,1,1,1}; int dfs(int i, int j) { int c = a[i][j]; a[i][j] = -1; int res = 1; rep(v,4) { int ni = i+di[v], nj = j+dj[v]; if (ni<0||nj<0||ni>=h||nj>=w) continue; if (a[ni][nj] != c) continue; res += dfs(ni,nj); } return res; } void efs(int i, int j, int x) { a[i][j] = x; rep(v,4) { int ni = i+di[v], nj = j+dj[v]; if (ni<0||nj<0||ni>=h||nj>=w) continue; if (a[ni][nj] != -1) continue; efs(ni,nj,x); } } int main() { scanf("%d%d",&h,&w); rep(i,h)rep(j,w) scanf("%d",&a[i][j]); int q; scanf("%d",&q); // uf t(h*w); // rep(i,h)rep(j,w) if (a[i][j]) t.d[i*w+j] = -2; int end = 0, col = 0; rep(qi,q) { int r, c, x; scanf("%d%d%d",&r,&c,&x); if (end) { col = x; continue; } --r; --c; if (x == a[r][c]) continue; int cnt = dfs(r,c); if (cnt == h*w) { end = 1; col = x; continue; } efs(r,c,x); } if (end) { rep(i,h)rep(j,w) a[i][j] = col;} rep(i,h) { vi x; rep(j,w) x.pb(a[i][j]); priv(x); } return 0; }