結果

問題 No.307 最近色塗る問題多くない?
ユーザー h_nosonh_noson
提出日時 2016-06-19 22:01:32
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 145 ms / 4,000 ms
コード長 1,495 bytes
コンパイル時間 530 ms
コンパイル使用メモリ 71,884 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-14 04:11:47
合計ジャッジ時間 2,982 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 17 ms
4,376 KB
testcase_09 AC 8 ms
4,376 KB
testcase_10 AC 4 ms
4,376 KB
testcase_11 AC 6 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 10 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 11 ms
4,380 KB
testcase_18 AC 26 ms
4,376 KB
testcase_19 AC 23 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 19 ms
4,380 KB
testcase_22 AC 17 ms
4,376 KB
testcase_23 AC 126 ms
4,384 KB
testcase_24 AC 49 ms
4,376 KB
testcase_25 AC 74 ms
4,376 KB
testcase_26 AC 141 ms
4,376 KB
testcase_27 AC 13 ms
4,376 KB
testcase_28 AC 20 ms
4,380 KB
testcase_29 AC 7 ms
4,376 KB
testcase_30 AC 145 ms
4,376 KB
testcase_31 AC 18 ms
4,380 KB
testcase_32 AC 17 ms
4,376 KB
testcase_33 AC 9 ms
4,376 KB
testcase_34 AC 17 ms
4,376 KB
testcase_35 AC 17 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
using namespace std;

#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP (i,0,(int)(n)-1)
#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP (i,(int)(n)-1,0)
#define INF (int)1e8
#define MOD (int)(1e9+7)

typedef long long ll;

int main(void) {
    int i, j, H, W;
    int A[200][200];
    scanf("%d%d",&H,&W);
    rep (i,H) rep (j,W) scanf("%d",&A[i][j]);

    int Q;
    scanf("%d",&Q);
    bool same = false;
    int X;
    while (Q--) {
        int R, C;
        scanf("%d%d%d",&R,&C,&X);
        R--; C--;
        if (same) continue;
        if (A[R][C] == X) continue;
        A[R][C] = X;
        queue<pair<int,int>> q;
        q.push(make_pair(R,C));
        int dxy[] = {1,0,-1,0};
        int cnt = 0;
        while (!q.empty()) {
            int y = q.front().first;
            int x = q.front().second;
            q.pop();
            rep (i,4) {
                int ny = y + dxy[i];
                int nx = x + dxy[(i+1)%4];
                if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
                if (A[ny][nx] != X) {
                    q.push(make_pair(ny,nx));
                    A[ny][nx] = X;
                }
            }
            cnt++;
        }
        if (cnt == H * W)
            same = true;
    }
    rep (i,H) {
        rep (j,W)
            printf("%d ",same ? X : A[i][j]);
        printf("\n");
    }
    return 0;
}
0