結果

問題 No.307 最近色塗る問題多くない?
ユーザー kzyKTkzyKT
提出日時 2015-11-28 00:51:11
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,922 bytes
コンパイル時間 1,660 ms
コンパイル使用メモリ 150,360 KB
実行使用メモリ 4,496 KB
最終ジャッジ日時 2023-10-12 01:04:39
合計ジャッジ時間 11,962 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 2 ms
4,368 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 995 ms
4,372 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 1,007 ms
4,368 KB
testcase_32 AC 15 ms
4,368 KB
testcase_33 WA -
testcase_34 AC 15 ms
4,368 KB
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
#define _(_1,_2,_3,N,...)N
#define pr(...) _(__VA_ARGS__,pr3,pr2,pr1)(__VA_ARGS__)
template<C T>void pr1(T a){cout<<a;ln;}
template<C T,C T2>void pr2(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr3(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n,m;
  cin >> n >> m;
  int a[n][m];
  rep(i,n)rep(j,m)cin >> a[i][j];
  int T;
  cin >> T;
  while(T--) {
    int x,y,z;
    cin >> x >> y >> z;
    x--,y--;
    if(a[x][y]==z) continue;
    int d[n][m];
    d[x][y]=0;
    a[x][y]=z;
    queue<P> que;
    que.push(P(x,y));
    while(!que.empty()) {
      P p=que.front();que.pop();
      int nx=p.F,ny=p.S;
      rep(i,4) {
        int xx=nx+dx[i],yy=ny+dy[i];
        if(!check(n,m,xx,yy)) continue;
        int c=d[nx][ny];
        if((z==a[xx][yy]&&c%2==0)||(z!=a[xx][yy]&&c%2==1)) c++;
        cerr << nx << " " << ny << " " << xx << " " << yy << " " << c << endl;
        if(c>1||d[xx][yy]<=c) continue;
        d[xx][yy]=c;
        a[xx][yy]=z;
        que.push(P(xx,yy));
      }
    }
  }
  rep(i,n)PR(a[i],m);
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}
0