結果

問題 No.307 最近色塗る問題多くない?
ユーザー imulanimulan
提出日時 2016-10-02 06:26:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 133 ms / 4,000 ms
コード長 1,662 bytes
コンパイル時間 1,642 ms
コンパイル使用メモリ 169,212 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-14 04:12:58
合計ジャッジ時間 3,948 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;

int main()
{
    int h,w;
    int a[200][200];
    scanf(" %d %d", &h, &w);
    rep(i,h)rep(j,w) scanf(" %d", &a[i][j]);

    #define IN(x,y) (0<=x && x<w && 0<=y && y<h)
    int dx[4]={1,-1,0,0}, dy[4]={0,0,1,-1};

    // クエリ処理
    bool all_done=false;
    int col=-1;

    int Q;
    scanf(" %d", &Q);

    while(Q--)
    {
        int r,c,x;
        scanf(" %d %d %d", &r, &c, &x);
        --r;
        --c;

        if(all_done)
        {
            col=x;
            continue;
        }

        if(a[r][c]==x) continue;

        queue<pi> que;
        que.push(pi(r,c));
        int vis_num=1;
        a[r][c]=x;
        while(!que.empty())
        {
            pi now=que.front();
            que.pop();
            rep(i,4)
            {
                int nx=now.se+dx[i], ny=now.fi+dy[i];
                if(IN(nx,ny) && a[ny][nx]!=x)
                {
                    a[ny][nx]=x;
                    que.push(pi(ny,nx));
                    ++vis_num;
                }
            }
        }

        if(vis_num==h*w)
        {
            all_done=true;
            col=x;
        }
    }

    // 出力
    rep(y,h)
    {
        rep(x,w)
        {
            if(x) printf(" ");
            if(all_done) a[y][x]=col;
            printf("%d", a[y][x]);
        }
        printf("\n");
    }
    return 0;
}
0