結果

問題 No.179 塗り分け
ユーザー imulan
提出日時 2016-02-05 22:38:34
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 99 ms / 3,000 ms
コード長 1,399 bytes
コンパイル時間 1,267 ms
コンパイル使用メモリ 163,132 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-23 14:33:50
合計ジャッジ時間 3,249 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define mp make_pair
#define pb push_back
#define fi first
#define sc second

int main(int argc, char const *argv[]) {
  int h,w;
  cin >>h >>w;
  std::vector<string> s(h);
  rep(i,h) cin >>s[i];

  int num=0;
  rep(i,h){
    rep(j,w){
      num+=(s[i][j]=='#');
    }
  }

  string ans="NO";

  if(num>0&&num%2==0){
    bool valid=false;

    for(int y=-(h-1); y<=h-1; ++y){//縦の平行移動幅
      for(int x=-(w-1); x<=w-1; ++x){//横の平行移動幅

        //printf("x,y=%d %d\n",x,y);

        int f[50][50]={0};
        int ct=0;
        rep(i,h){
          rep(j,w){

            if(0<=i+y&&i+y<h&&0<=j+x&&j+x<w){
              if(s[i][j]=='#'&&s[i+y][j+x]=='#'){
                if(f[i][j]==0&&f[i+y][j+x]==0){
                  /*
                  printf(" (%d, %d) ->",i,j);
                  printf(" (%d, %d)\n",i+y,j+x);
                  */
                  f[i][j]=1;
                  f[i+y][j+x]=2;
                  ++ct;
                }
              }
            }

          }
        }


        if(ct==num/2){
          valid=true;
          break;
        }
      }
      if(valid) break;
    }

    if(valid) ans="YES";
  }

  std::cout << ans << std::endl;
  return 0;
}
0