結果
| 問題 |
No.307 最近色塗る問題多くない?
|
| コンテスト | |
| ユーザー |
cormoran
|
| 提出日時 | 2016-03-01 23:28:16 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,062 bytes |
| コンパイル時間 | 942 ms |
| コンパイル使用メモリ | 81,092 KB |
| 実行使用メモリ | 14,016 KB |
| 最終ジャッジ日時 | 2024-09-24 13:20:39 |
| 合計ジャッジ時間 | 12,443 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 24 TLE * 2 -- * 10 |
ソースコード
// 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;
bool spread(int x, int y, int nxt_color){
int prev_color = G[y][x];
if(prev_color == nxt_color) return false;
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);
}
}
}
return true;
}
bool solve(){
cin >> H >> W;
G.resize(H, vector<int>(W));
rep(i, H) cin >> G[i];
int Q; cin >> Q;
int cnt = 0;
bool ended = false;
int last_color = 0;
rep(i, Q){
int y, x, c; cin >> y >> x >> c;
y--; x--;
if(not ended)cnt += spread(x, y, c);
if(cnt >= H * W) ended = true;
last_color = c;
}
rep(y, H){
rep(x, W){
cout << (ended ? last_color : G[y][x]) << (x != W-1 ? " " : "\n");
}
}
return false;
}
int main()
{
ios::sync_with_stdio(false);
while(solve());
return 0;
}
cormoran