結果
問題 |
No.307 最近色塗る問題多くない?
|
ユーザー |
![]() |
提出日時 | 2015-11-27 06:06:16 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,212 bytes |
コンパイル時間 | 642 ms |
コンパイル使用メモリ | 63,484 KB |
実行使用メモリ | 13,980 KB |
最終ジャッジ日時 | 2024-09-13 23:01:45 |
合計ジャッジ時間 | 7,268 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 TLE * 2 -- * 10 |
コンパイルメッセージ
main.cpp: In function ‘int main_()’: main.cpp:30:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 30 | scanf("%d%d", &h,&w); | ~~~~~^~~~~~~~~~~~~~~ main.cpp:34:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 34 | scanf("%d", &a[i][j]); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp:42:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 42 | scanf("%d", &q); | ~~~~~^~~~~~~~~~ main.cpp:45:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 45 | scanf("%d%d%d", &r,&c,&x); | ~~~~~^~~~~~~~~~~~~~~~~~~~
ソースコード
#include <iostream> #include <vector> #include <cstdio> #include <ctime> using namespace std; int dx[] = {0,0,1,-1,0,0}; int* dy = dx+2; int h,w; int dfs(vector<vector<int>>& a, int r, int c, int col){ if(a[r][c] == col) return 0; a[r][c] = col; int ret = 1; for(int k__=0; k__<4; k__++){ int new_x = c + dx[k__]; int new_y = r + dy[k__]; if(new_x < 0 || new_x >= w || new_y < 0 || new_y >= h) continue; if(a[new_y][new_x] == col) continue; ret += dfs(a, new_y, new_x, col); } return ret; } int main_(){ scanf("%d%d", &h,&w); vector<vector<int>> a(h, vector<int>(w)); for(int i=0; i<h; i++){ for(int j=0; j<w; j++){ scanf("%d", &a[i][j]); } } bool filled = false; int last = -1; int q; scanf("%d", &q); while(q--){ int r,c,x; scanf("%d%d%d", &r,&c,&x); r--; c--; last = x; //if(filled) continue; int cnt = dfs(a,r,c, x); filled = cnt == h*w; } if(filled){ for(int i=0; i<h; i++){ fill(a[i].begin(), a[i].end(), last); } } for(int i=0; i<h; i++){ for(int j=0; j<w; j++){ printf("%d%s", a[i][j], (j==w-1)?"\n":" "); } } return 0; } int main(){ auto start = clock(); main_(); cerr << clock() - start << " [ms]" << endl; return 0; }