結果

問題 No.307 最近色塗る問題多くない?
ユーザー ctyl_0ctyl_0
提出日時 2015-11-29 00:19:02
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,403 bytes
コンパイル時間 756 ms
コンパイル使用メモリ 95,556 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-12 05:34:46
合計ジャッジ時間 3,705 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 28 ms
4,352 KB
testcase_08 AC 243 ms
4,352 KB
testcase_09 AC 110 ms
4,352 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 20 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 4 ms
4,356 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 13 ms
4,348 KB
testcase_18 AC 34 ms
4,348 KB
testcase_19 AC 30 ms
4,352 KB
testcase_20 AC 2 ms
4,352 KB
testcase_21 AC 25 ms
4,348 KB
testcase_22 AC 22 ms
4,348 KB
testcase_23 AC 159 ms
4,352 KB
testcase_24 AC 63 ms
4,348 KB
testcase_25 AC 51 ms
4,352 KB
testcase_26 AC 190 ms
4,348 KB
testcase_27 WA -
testcase_28 AC 29 ms
4,352 KB
testcase_29 AC 15 ms
4,352 KB
testcase_30 AC 195 ms
4,352 KB
testcase_31 WA -
testcase_32 AC 33 ms
4,348 KB
testcase_33 AC 11 ms
4,352 KB
testcase_34 AC 33 ms
4,352 KB
testcase_35 AC 33 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define var auto
#define mod 1000000007
#define inf 2147483647
#define nil -1
typedef long long ll;

using namespace std;

inline int input(){
    int a;
    cin >> a;
    return a;
}

template <typename T>
inline void output(T a, int p) {
    if(p){
        cout << fixed << setprecision(p)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

// end of template

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
    cin.tie(0);
    // source code
    int H = input();
    int W = input();
    vector<vector<int>> A(H, vector<int>(W));
    
    rep(i, H){
        rep(j, W){
            cin >> A[i][j];
        }
    }
    
    int Q;
    cin >> Q;
    queue<pair<int, int>> q;
    
    vector<int> R(Q), C(Q), X(Q);
    int count = 0; // 盤面が変化した回数
    
    rep(i, Q){
        cin >> R[i] >> C[i] >> X[i];
        R[i]--, C[i]--;
    }
    
    rep(i, Q){
        if (A[R[i]][C[i]] == X[i]) continue;
        
        // A[R][C] != X
        
        if (count > H + W) {
            break;
        }
        count++;
        q.push(make_pair(R[i], C[i]));
        A[R[i]][C[i]] = X[i];
        while (!q.empty()) {
            pair<int, int> t = q.front();
            q.pop();
            rep(j, 4){
                if (t.first + dy[j] >= 0 && t.first + dy[j] < H && t.second + dx[j] >= 0 && t.second + dx[j] < W && A[t.first + dy[j]][t.second + dx[j]] != X[i]) { // 隣接している,かつXと違う色のマスを訪れる
                    A[t.first + dy[j]][t.second + dx[j]] = X[i];
                    q.push(make_pair(t.first + dy[j], t.second + dx[j]));
                }
            }
        }
        
    }
    
    if (count <= H + W) {
        rep(i, H){
            rep(j, W){
                if (j) cout << " ";
                cout << A[i][j];
            }
            cout << endl;
        }
    }
    else{
        rep(i, H){
            rep(j, W){
                if (j) cout << " ";
                cout << X[Q - 1];
            }
            cout << endl;
        }
    }
    
    
    
    
    return 0;
}
0