結果

問題 No.307 最近色塗る問題多くない?
ユーザー cormorancormoran
提出日時 2016-03-01 21:41:41
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,868 bytes
コンパイル時間 725 ms
コンパイル使用メモリ 81,236 KB
実行使用メモリ 6,652 KB
最終ジャッジ日時 2023-10-24 19:21:48
合計ジャッジ時間 8,260 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 214 ms
4,348 KB
testcase_08 TLE -
testcase_09 AC 418 ms
5,148 KB
testcase_10 AC 4 ms
4,348 KB
testcase_11 AC 6 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 35 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 10 ms
4,964 KB
testcase_18 AC 25 ms
5,972 KB
testcase_19 AC 24 ms
6,080 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 18 ms
5,476 KB
testcase_22 AC 18 ms
6,616 KB
testcase_23 AC 119 ms
6,652 KB
testcase_24 AC 43 ms
5,476 KB
testcase_25 TLE -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

//  yukicoder -  - 307  / 2016-03-01
#include<iostream>
#include<vector>
#include<cassert>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<tuple>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef ll int__;
#define rep(i,j) for(int__ i=0;i<(int__)(j);i++)
#define repeat(i,j,k) for(int__ i=(j);i<(int__)(k);i++)
#define all(v) v.begin(),v.end()

template<typename T>ostream& operator << (ostream &os , const vector<T> &v){
    rep(i,v.size()) os << v[i] << (i!=v.size()-1 ? " " : "\n"); return os;
}
template<typename T>istream& operator >> (istream &is , vector<T> &v){
    rep(i,v.size()) is >> v[i]; return is;
}

#ifdef DEBUG
void debug(){ cerr << endl; }
#endif
template<class F,class...R> void debug(const F &car,const R&... cdr){
#ifdef DEBUG
    cerr << car << " "; debug(cdr...);
#endif
}


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

int H, W;
vector<vector<int>> G;


void spread(int x, int y, int nxt_color){
    int prev_color = G[y][x];
    if(prev_color == nxt_color) return;
    G[y][x] = nxt_color;
    rep(dir, 4){
        int nx = x + dx[dir];
        int ny = y + dy[dir];
        if(0 <= nx and nx < W and
           0 <= ny and ny < H){
            if(G[ny][nx] == prev_color){
                spread(nx, ny, nxt_color);
            }
        }
    }
}

bool solve(){
    cin >> H >> W;
    G.resize(H, vector<int>(W));
    rep(i, H) cin >> G[i];

    int Q; cin >> Q;
    rep(i, Q){
        int y, x, c; cin >> y >> x >> c;
        y--; x--;
        spread(x, y, c);
    }

    rep(y, H){
        rep(x, W){
            cout << G[y][x] << (x != W-1 ? " " : "\n");
        }
    }
    
    return false;
}

int main()
{
    ios::sync_with_stdio(false);
    while(solve());
    return 0;
}
0