結果

問題 No.307 最近色塗る問題多くない?
ユーザー ctyl_0ctyl_0
提出日時 2015-11-28 21:57:36
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,980 bytes
コンパイル時間 2,169 ms
コンパイル使用メモリ 93,936 KB
実行使用メモリ 486,628 KB
最終ジャッジ日時 2023-10-12 05:33:24
合計ジャッジ時間 7,090 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;
    int count = 0; // 盤面が変化した回数
    queue<pair<int, int>> q;
    
    rep(i, Q) {
        int R, C, X;
        cin >> R >> C >> X;
        R--, C--;
        if (count > H + W) break;
        if (A[R][C] == X) continue;
        // BFS
        q.push(make_pair(R, C));
        A[R][C] = X;
        while (!q.empty()) {
            var 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) { // 隣接している,かつXと違う色のマスを訪れる
                    A[t.first][t.second] = X;
                    q.push(make_pair(t.first + dy[j], t.second + dx[j]));
                }
            }
        }
        count++;
    }
    
    rep(i, H){
        rep(j, W){
            if (j) cout << " ";
            cout << A[i][j];
        }
        cout << endl;
    }
    
    
    return 0;
}
0