結果

問題 No.2641 draw X
ユーザー otoshigootoshigo
提出日時 2024-02-20 00:04:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,983 bytes
コンパイル時間 1,317 ms
コンパイル使用メモリ 96,016 KB
実行使用メモリ 36,020 KB
最終ジャッジ日時 2024-02-20 00:04:32
合計ジャッジ時間 3,587 ms
ジャッジサーバーID
(参考情報)
judge16 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 WA -
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 1 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 1 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 33 ms
36,020 KB
testcase_16 WA -
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 6 ms
6,676 KB
testcase_21 AC 11 ms
8,320 KB
testcase_22 AC 5 ms
6,676 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 4 ms
6,676 KB
testcase_26 WA -
testcase_27 AC 4 ms
6,676 KB
testcase_28 AC 16 ms
14,592 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 25 ms
17,408 KB
testcase_32 WA -
testcase_33 AC 53 ms
28,644 KB
testcase_34 AC 31 ms
17,792 KB
testcase_35 AC 29 ms
16,128 KB
testcase_36 WA -
testcase_37 AC 64 ms
34,276 KB
testcase_38 AC 45 ms
30,828 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 50 ms
32,228 KB
testcase_43 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using ll=long long;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

struct UnionFind {
private:
    vector<int> par, siz;

public:
    UnionFind(int n) : par(n, -1), siz(n, 1) {}
    int find(int x) {
        if (par[x] == -1) return x;
        else {
            par[x] = find(par[x]);
            return par[x];
        }
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    int size(int x) {
        return siz[find(x)];
    }
    bool merge(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }
};

const int INF=1<<30;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H,W;
    cin>>H>>W;
    vector<string>S(H);
    for(int i=0;i<H;i++)cin>>S[i];
    UnionFind uf1(H*W),uf2(H*W);
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(S[i][j]=='#'){
                if(i+1<H&&j+1<W&&S[i+1][j+1]=='#'){
                    uf1.merge(W*i+j,W*(i+1)+j+1);
                }
                if(i+1<H&&j-1>=0&&S[i+1][j-1]=='#'){
                    uf2.merge(W*i+j,W*(i+1)+j-1);
                }
            }
        }
    }
    vector<int>min1(H*W,INF),max1(H*W,-INF),min2(H*W,INF),max2(H*W,-INF);
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            chmin(min1[uf1.find(W*i+j)],i);
            chmax(max1[uf1.find(W*i+j)],i);
            chmin(min2[uf2.find(W*i+j)],i);
            chmax(max2[uf2.find(W*i+j)],i);
        }
    }
    vector flag1(H,vector<bool>(W));
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(flag1[i][j]||S[i][j]=='.')continue;
            int l1=uf1.find(W*i+j);
            if(min1[l1]==INF)continue;
            vector<pair<int,int>>vp;
            for(int k=min1[l1];k<=max1[l1];k++){
                flag1[k][j-i+k]=true;
                int l2=uf2.find(W*k+(j-i+k));
                if(min2[l2]==INF)continue;
                int a=min(k-min2[l2],max2[l2]-k);
                if(min2[l2]!=max2[l2]){
                    vp.push_back(make_pair(k-a,k+a));
                }
            }
            if(vp.empty()){
                cout<<"No"<<"\n";
                return 0;
            }
            sort(all(vp));
            int l=vp[0].first,r=vp[0].second;
            for(int k=1;k<vp.size();k++){
                if(r<vp[k].first)break;
                chmax(r,vp[k].second);
            }
            if(!(l<=min1[l1]&&max1[l1]<=r)){
                cout<<"No"<<"\n";
                return 0;
            }
        }
    }
    vector flag2(H,vector<bool>(W));
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(flag2[i][j]||S[i][j]=='.')continue;
            int l2=uf2.find(W*i+j);
            if(min2[l2]==INF)continue;
            vector<pair<int,int>>vp;
            for(int k=min2[l2];k<=max2[l2];k++){
                flag2[k][j+i-k]=true;
                int l1=uf1.find(W*k+(j+i-k));
                if(min1[l1]==INF)continue;
                int a=min(k-min1[l1],max1[l1]-k);
                if(min1[l1]!=max1[l1]){
                    vp.push_back(make_pair(k-a,k+a));
                }
            }
            if(vp.empty()){
                cout<<"No"<<"\n";
                return 0;
            }
            sort(all(vp));
            int l=vp[0].first,r=vp[0].second;
            for(int k=1;k<vp.size();k++){
                if(r<vp[k].first)break;
                chmax(r,vp[k].second);
            }
            if(!(l<=min2[l2]&&max2[l2]<=r)){
                cout<<"No"<<"\n";
                return 0;
            }
        }
    }
    cout<<"Yes"<<"\n";
}
0