結果

問題 No.179 塗り分け
ユーザー 48025254802525
提出日時 2019-03-31 17:19:00
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 178 ms / 3,000 ms
コード長 1,374 bytes
コンパイル時間 1,256 ms
コンパイル使用メモリ 149,260 KB
実行使用メモリ 6,440 KB
最終ジャッジ日時 2023-09-30 21:10:02
合計ジャッジ時間 3,110 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 8 ms
6,440 KB
testcase_11 AC 7 ms
5,920 KB
testcase_12 AC 178 ms
5,996 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 4 ms
4,696 KB
testcase_19 AC 4 ms
4,576 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 4 ms
4,504 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 5 ms
4,836 KB
testcase_31 AC 4 ms
4,376 KB
testcase_32 AC 5 ms
5,080 KB
testcase_33 AC 5 ms
4,520 KB
testcase_34 AC 5 ms
5,340 KB
testcase_35 AC 5 ms
4,468 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
typedef long long ll;
typedef pair<int, int> P;
typedef struct{
  int first;
  int second;
  int third;
}T;

//昇順
bool comp_Se(T& l, T& r){
  return l.second < r.second;
}

int H,W;
vector<char>S;
vector<int> v;

//cur 新しく赤を塗った位置
//dx,dy移動先
bool dfs(int cur, int dx, int dy, vector<char>color){
  int j = v[cur]%H+dx, k = v[cur]/H+dy;
  //移動先が範囲外j
  if(j >= H || k >=W || k < 0) return false;
  //移動先が黒じゃない
  int l = k*H+j;
  if(color[l] != '#') return false;
  //青で塗る
  color[l] = 'B';
  //次の黒を探す(
  cur++;
  while( cur != v.size() && color[v[cur]] != '#') cur++;

  if(cur==v.size()) return true;
  color[v[cur]] = 'R';
  return dfs(cur, dx, dy, color);
}

int main(void){
  cin >> W >> H;
  S = vector<char>(W*H);
  int i;
  REP(i,H*W){
    cin >> S[i];
    if(S[i] == '#') v.push_back(i);
  }

  //黒がないまたは奇数なら作れない
  if(v.size()%2 || v.size() == 0){
    cout << "NO" << endl;
    return 0;
  }

  //以降黒は2以上の偶数

  vector<char> color = S;
  color[v[0]] = 'R';
  for(i=1;i<v.size();i++){
    int dx = v[i]%H - v[0]%H, dy = v[i]/H - v[0]/H;
    if(dfs(0,dx,dy,color)){   
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}
0