結果

問題 No.179 塗り分け
ユーザー umezo
提出日時 2022-02-16 06:58:53
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 23 ms / 3,000 ms
コード長 1,116 bytes
コンパイル時間 2,161 ms
コンパイル使用メモリ 203,096 KB
最終ジャッジ日時 2025-01-27 23:19:34
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int h,w;
  cin>>h>>w;
  vector<string> S(h);
  rep(i,h) cin>>S[i];
  
  vector<pair<int,int>> A;
  rep(i,h) rep(j,w){
    if(S[i][j]=='#') A.push_back({j,i});
  }
  sort(ALL(A));
  
  int n=A.size();
  if(n%2==1 || n==0) cout<<"NO"<<endl;
  else if(n==2) cout<<"YES"<<endl;
  else{
    int y=A[0].first,x=A[0].second;
    for(int i=1;i<n;i++){
      vector<string> T(h);
      rep(j,h) T[j]=S[j];
      int dx=A[i].second-x,dy=A[i].first-y;
      bool b=true;
      for(int j=1;j<n;j++){
        if(j==i) continue;
        if(T[A[j].second][A[j].first]=='.') continue;
        int nx=A[j].second+dx,ny=A[j].first+dy;
        if(nx<0 || nx>=h || ny<0 || ny>=w){
          b=false;
          continue;
        }
        if(T[nx][ny]=='#') T[nx][ny]='.';
        else b=false;
      }
      if(b){
        cout<<"YES"<<endl;
        return 0;
      }
    }
    cout<<"NO"<<endl;
  }

  return 0;
}
0