結果
問題 | No.307 最近色塗る問題多くない? |
ユーザー |
|
提出日時 | 2016-03-08 00:27:11 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 130 ms / 4,000 ms |
コード長 | 2,061 bytes |
コンパイル時間 | 1,463 ms |
コンパイル使用メモリ | 160,084 KB |
実行使用メモリ | 8,064 KB |
最終ジャッジ日時 | 2024-11-21 22:16:21 |
合計ジャッジ時間 | 3,167 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 36 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:74:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 74 | scanf("%d",&H); | ~~~~~^~~~~~~~~ main.cpp:75:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 75 | scanf("%d",&W); | ~~~~~^~~~~~~~~ main.cpp:78:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 78 | scanf("%d",&A[i][j]); | ~~~~~^~~~~~~~~~~~~~~ main.cpp:81:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 81 | scanf("%d",&Q); | ~~~~~^~~~~~~~~ main.cpp:85:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 85 | scanf("%d %d %d",&R,&C,&X); | ~~~~~^~~~~~~~~~~~~~~~~~~~~ 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); | ~~~~~^~~~~~~~~~~~~~~~~~~~~
ソースコード
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #ifdef _MSC_VER #include "bits\stdc++.h" #else #include <bits/stdc++.h> #endif #include <vector> #include <set> #include <string> #include <queue> #include <list> #define REP(i,a,b) for(i=a;i<b;i++) #define rep(i,n) REP(i,0,n) // #define rep(i,n) REP(i,1,n) #define ll long long #define ull unsigned ll typedef long double ld; #define SQR(X) ( (X)*(X) ) #define CUBE(X) ( (X)*(X)*(X) ) // #define int ll using namespace std; bool test = 0; /* ここからが本編 */ /* pow(x,n)はx^nを返すよ! */ static int A[200][200]; int H,W; int target_color; int next_color; void print_map() { int i,j; if(test) puts("---map---"); for(i=0;i<H;i++) { printf("%d",A[i][0]); for(j=1;j<W;j++) { printf(" %d",A[i][j]); } puts(""); } if(test) puts("---------"); } int draw(int R, int C) { int a = 1; if(test) { printf("A[%d][%d] = %d ",R,C,A[R][C]); printf("target_color = %d\n",target_color); } A[R][C] = next_color; if(test) { printf("R = %d C = %d\n",R,C); } if(R-1 > -1 && A[R-1][C] == target_color) { a += draw(R-1,C); } if(R+1 < H && A[R+1][C] == target_color) { a += draw(R+1,C); } if(C-1 > -1 && A[R][C-1] == target_color) { a += draw(R,C-1); } if(C+1 < W && A[R][C+1] == target_color) { a += draw(R,C+1); } return a; } int main(void) { int i,j,k,l; int Q; scanf("%d",&H); scanf("%d",&W); for(i=0;i<H;i++) { for(j=0;j<W;j++) { scanf("%d",&A[i][j]); } } scanf("%d",&Q); int R,C,X; bool all_draw = false; for(i=0;i<Q;i++) { scanf("%d %d %d",&R,&C,&X); R--;C--; int a = 0; if(A[R][C] != X) { target_color = A[R][C]; next_color = X; a = draw(R,C); if(test) print_map(); } if(a == H*W) { all_draw = true; break; } } for(;i<Q;i++) { scanf("%d %d %d",&R,&C,&X); } if(all_draw) { rep(i,H) rep(j,W) { A[i][j] = X; } } if(test) cout << "all_draw = " << all_draw << endl; print_map(); return 0; }