結果

問題 No.307 最近色塗る問題多くない?
ユーザー ctyl_0ctyl_0
提出日時 2015-11-29 01:16:10
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,046 bytes
コンパイル時間 747 ms
コンパイル使用メモリ 94,608 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2023-10-12 05:35:32
合計ジャッジ時間 6,638 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,704 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 255 ms
4,352 KB
testcase_08 TLE -
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;
    queue<pair<int, int>> q;
    
    vector<int> R(Q), C(Q), X(Q);
    
    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
        
        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]));
                }
            }
        }
    }
    
    rep(i, H){
        rep(j, W){
            if (j) cout << " ";
            cout << A[i][j];
        }
        cout << endl;
    }
    
    
    
    
    
    
    
    return 0;
}
0