結果

問題 No.1954 CHECKER×CHECKER(2)
ユーザー 蜜蜂蜜蜂
提出日時 2022-05-19 12:44:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 2,400 bytes
コンパイル時間 4,825 ms
コンパイル使用メモリ 236,456 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 21:28:54
合計ジャッジ時間 5,944 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//g++ 2.cpp -std=c++14 -O2 -I .
#include <bits/stdc++.h>
using namespace std;

#include <atcoder/all>
using namespace atcoder;

using ll = long long;
using ld = long double;
 
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vst = vector<string>;
using vvst = vector<vst>;
 
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define pq_big(T) priority_queue<T,vector<T>,less<T>>
#define pq_small(T) priority_queue<T,vector<T>,greater<T>>
#define all(a) a.begin(),a.end()
#define rep(i,start,end) for(ll i=start;i<(ll)(end);i++)
#define per(i,start,end) for(ll i=start;i>=(ll)(end);i--)
#define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end())

char op(char c){
  if(c=='#'){
    return '.';
  }
  return '#';
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int h,w;
  cin>>h>>w;

  vst grid(h);
  rep(i,0,h){
    cin>>grid[i];
  }

  rep(i,0,h){
    rep(j,0,w){
      if((i+j)%2){
        grid[i][j]=op(grid[i][j]);
      }
    }
  }

  int m;
  cin>>m;

  vi t1={0},t2={0};
  rep(i,0,m){
    int t,n;
    cin>>t>>n;
    if(t==1&&n<h){
      t1.emplace_back(n);
    }
    else if(t==2&&n<w){
      t2.emplace_back(n);
    }
  }

  sort(all(t1));
  sort(all(t2));

  rep(i,0,h){
    rep(j,0,w-1){
      if(grid[i][j]!=grid[i][j+1]){
        bool flg=0;
        for(int v:t2){
          if(j+1==v){
            flg=1;
          }
        }
        if(flg==0){
          cout<<"No\n";
          return 0;
        }
      }
    }
  }

  rep(i,0,h-1){
    rep(j,0,w){
      if(grid[i][j]!=grid[i+1][j]){
        bool flg=0;
        for(int v:t1){
          if(i+1==v){
            flg=1;
          }
        }
        if(flg==0){
          cout<<"No\n";
          return 0;
        }
      }
    }
  }

  vst grid2;
  for(int v:t1){
    string s="";
    for(int w:t2){
      s+=grid[v][w];
    }
    grid2.emplace_back(s);
  }

  int h2=grid2.size(),w2=grid2[0].size();
  rep(i,0,h2){
    if(grid2[i][0]=='#'){
      rep(j,0,w2){
        grid2[i][j]=op(grid2[i][j]);
      }
    }
  }
  rep(j,0,w2){
    if(grid2[0][j]=='#'){
      rep(i,0,h2){
        grid2[i][j]=op(grid2[i][j]);
      }
    }
  }

  rep(i,0,h2){
    rep(j,0,w2){
      if(grid2[0][0]!=grid2[i][j]){
        cout<<"No\n";
        return 0;
      }
    }
  }
  cout<<"Yes\n";
}
0