結果
| 問題 |
No.307 最近色塗る問題多くない?
|
| コンテスト | |
| ユーザー |
treeone
|
| 提出日時 | 2016-05-02 23:19:05 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,165 bytes |
| コンパイル時間 | 1,100 ms |
| コンパイル使用メモリ | 163,020 KB |
| 実行使用メモリ | 13,600 KB |
| 最終ジャッジ日時 | 2024-10-05 02:33:17 |
| 合計ジャッジ時間 | 7,138 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 8 TLE * 1 -- * 27 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int a[210][210];
int dy[4]={1,-1,0,0};
int dx[4]={0,0,1,-1};
int h,w,q;
bool f[210][210];
void dfs(int r,int c,int color,int x,int sum){
f[r][c]=true;
sum+=x-color;
a[r][c]=x;
rep(i,0,4){
int ny=r+dy[i];
int nx=c+dx[i];
if(0<=ny && ny<h && 0<=nx && nx<w && a[ny][nx]==color && f[ny][nx]==false){
dfs(ny,nx,color,x,sum);
}
}
return;
}
signed main(){
cin>>h>>w;
int sum=0;
rep(i,0,h) rep(j,0,w){
cin>>a[i][j]; sum+=a[i][j];
}
cin>>q;
vi r(q),c(q),x(q);
rep(i,0,q){
cin>>r[i]>>c[i]>>x[i];
}
bool g=false;
rep(i,0,q){
r[i]--; c[i]--;
int color=a[r[i]][c[i]];
rep(k,0,h) rep(j,0,w) f[k][j]=false;
dfs(r[i],c[i],color,x[i],sum);
if(sum==h*w||sum==0){
g=true; break;
}
}
if(g){
rep(i,0,h) rep(j,0,w) a[i][j]=x[q-1];
}
rep(i,0,h){
rep(j,0,w){
cout<<(j?" ":"")<<a[i][j];
}
cout<<endl;
}
}
treeone