結果
| 問題 | No.307 最近色塗る問題多くない? |
| コンテスト | |
| ユーザー |
okaduki
|
| 提出日時 | 2015-11-28 00:23:55 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 150 ms / 4,000 ms |
| コード長 | 1,752 bytes |
| コンパイル時間 | 1,186 ms |
| コンパイル使用メモリ | 160,784 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-21 21:56:28 |
| 合計ジャッジ時間 | 3,332 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 36 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
int dx[] = {-1,1,0,0};
int dy[] = {0,0,-1,1};
int col[200][200];
bool use[200][200];
int H, W;
int dfs(int x, int y, int c){
if(col[y][x] == c) return 0;
col[y][x] = c;
int sum = 1;
REP(i,4){
int tx= x+dx[i], ty=y+dy[i];
if(tx<0||W<=tx||ty<0||H<=ty||use[ty][tx]) continue;
use[ty][tx] = true;
sum += dfs(tx,ty,c);
}
return sum;
}
int main(){
cin.tie(0);
ios_base::sync_with_stdio(false);
cin >> H >> W;
REP(y,H) REP(x,W){
cin >> col[y][x];
}
int Q; cin >> Q;
bool fin = false;
int c;
while(Q--){
int y, x; cin >> y >> x >> c;
--y,--x;
if(!fin && col[y][x] != c){
fill((bool*)use, (bool*)use+200*200, false);
use[y][x] = true;
fin = dfs(x,y,c) == W*H;
}
}
if(fin){
REP(y,H){
REP(x,W) cout << (x==0?"":" ") << c;
cout << endl;
}
}
else
REP(y,H){
REP(x,W) cout << (x==0?"":" ") << col[y][x];
cout << endl;
}
return 0;
}
okaduki