結果

問題 No.307 最近色塗る問題多くない?
ユーザー koba-e964koba-e964
提出日時 2015-12-04 14:42:57
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,045 bytes
コンパイル時間 818 ms
コンパイル使用メモリ 95,340 KB
実行使用メモリ 493,972 KB
最終ジャッジ日時 2023-10-12 14:04:10
合計ジャッジ時間 9,162 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,356 KB
testcase_01 AC 1 ms
4,356 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 17 ms
4,348 KB
testcase_08 AC 34 ms
4,356 KB
testcase_09 AC 8 ms
4,352 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 157 ms
6,932 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 37 ms
4,352 KB
testcase_26 WA -
testcase_27 AC 22 ms
4,352 KB
testcase_28 MLE -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef pair<int, int> PI;
const double EPS=1e-9;


VI a[201];
int h,w;

int get_col(int x, int y) {
    if (x < 0 || x >= h || y < 0 || y >= h) {
        return -1;
    }
    return a[x][y];
}

int main(void){
    cin >> h >> w;
    REP(i, 0, h) {
        a[i].reserve(w);
        REP(j, 0, w) {
            int b;
            cin >> b;
            a[i].push_back(b);
        }
    }
    int q;
    int saturated = 0;
    int sat_col = -1;
    cin >> q;
    REP(loop, 0, q) {
        int r,c,x;
        cin >> r >> c >> x;
        r--,c--;
        if (saturated) {
            sat_col = x;
            continue;
        }
        int col = a[r][c];
        if (x == col) {
            continue;
        }
        int dir[5] = {0,1,0,-1,0};
        queue<PI> que;
        que.push(PI(r, c));
        int cnt = 0;
        while (!que.empty()) {
            PI t = que.front(); que.pop();
            int x = t.first, y = t.second;
            REP(d, 0, 4) {
                int dx = dir[d], dy = dir[d + 1];
                if (get_col(x + dx, y + dy) == col) {
                    que.push(PI(x + dx, y + dy));
                }
            }
            a[x][y] = 1 - col;
            cnt++;
        }
        if (cnt >= w * h) {
            saturated = 1;
            sat_col = a[r][c];
        }
    }
    REP(i, 0, h) {
        REP(j, 0, w) {
            if (saturated) {
                a[i][j] = sat_col;
            }
            cout << a[i][j] << (j == w - 1 ? "\n" : " ");
        }
    }
}
0