結果

問題 No.307 最近色塗る問題多くない?
ユーザー tottoripaper
提出日時 2015-11-27 23:20:22
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 999 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 23,936 KB
実行使用メモリ 13,880 KB
最終ジャッジ日時 2024-09-14 00:39:40
合計ジャッジ時間 6,473 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 8 TLE * 1 -- * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:27:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   27 |     scanf("%d %d", &H, &W);
      |     ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:31:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   31 |             scanf("%d", &A[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~~
main.cpp:35:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   35 |     scanf("%d", &Q);
      |     ~~~~~^~~~~~~~~~
main.cpp:37:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   37 |         scanf("%d %d %d", &R, &C, &X);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <cstring>

const int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
int H, W, Q, R, C, X;
int A[200][200];
bool _array[200][200];

void dfs(int r, int c, int prevColor, int color){
    _array[r][c] = 1;
    A[r][c] = color;

    
    for(int i=0;i<4;i++){
        int nr = r + dx[i], nc = c + dy[i];
        
        if(!_array[nr][nc] &&
           0 <= nr && nr < H &&
           0 <= nc && nc < W &&
           A[nr][nc] == prevColor){
            dfs(nr, nc, prevColor, color);
        }
    }
}

int main(){
    scanf("%d %d", &H, &W);
    
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            scanf("%d", &A[i][j]);
        }
    }

    scanf("%d", &Q);
    for(int i=0;i<Q;i++){
        scanf("%d %d %d", &R, &C, &X);

        --R; --C;
        dfs(R, C, A[R][C], X);

        memset(_array, 0, sizeof(_array));
    }

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            printf("%d%c", A[i][j], j+1==W?'\n':' ');
        }
    }    
}
0