結果

問題 No.307 最近色塗る問題多くない?
ユーザー d2verbd2verb
提出日時 2015-11-28 00:38:06
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,244 bytes
コンパイル時間 724 ms
コンパイル使用メモリ 94,360 KB
実行使用メモリ 9,312 KB
最終ジャッジ日時 2023-10-12 00:53:00
合計ジャッジ時間 6,928 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <numeric>
#include <ctime>
#include <bitset>
#include <cctype>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>

using namespace std;

//define
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define dump(x)  cerr << #x << " = " << (x) << endl;

#define INF (INT_MAX/2)
#define PI (2*acos(0.0))
#define EPS (1e-8)

#define REP(i,a,b) for(int i=(a); i<(b);++i)
#define rep(i,n) REP(i,0,n)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;

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

int H, W;
int cnt_zero;
vvint A;

void dfs(int r, int c, int x){
  int color = A[r][c];
  A[r][c] = x;
  if(color == 0 && A[r][c] == 1) cnt_zero--;
  if(color == 1 && A[r][c] == 0) cnt_zero++;
  for(int i = 0; i < 4; i++){
    int nr = r + dy[i];
    int nc = c + dx[i];
    if(0 <= nr && nr < H && 0 <= nc && nc < W && A[nr][nc] == color && A[nr][nc] != x){
      dfs(nr, nc, x);
    }
  }
}

int main(void){
  ios_base::sync_with_stdio(0);
  cin >> H >> W;
  A = vvint(H);
  int input;
  
  rep(i, H){
    rep(j, W){
      cin >> input;
      if(input == 0) cnt_zero++;
      A[i].push_back(input);
    }
  }
  
  int Q, R, C, X;
  int all = -1;
  cin >> Q;
  rep(i, Q){
    cin >> R >> C >> X;
    R--;  C--;
    if(cnt_zero != H * W || cnt_zero != 0) dfs(R, C, X);
    else if(cnt_zero == H * W && X == 1) all = 1;
    else if(cnt_zero == 0 && X == 0) all = 0;
  }

  if(all == -1){
    rep(i, H){
      rep(j, W){
        if(j) cout << " ";
        cout << A[i][j];
      }
      cout << endl;
    }
  }else{
    rep(i, H){
      rep(j, W){
        if(j) cout << " ";
        cout << all;
      }
      cout << endl;
    }
  }
  return 0; 
}
0