結果

問題 No.2641 draw X
ユーザー RubikunRubikun
提出日時 2024-02-19 21:38:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 3,334 bytes
コンパイル時間 2,540 ms
コンパイル使用メモリ 218,520 KB
実行使用メモリ 35,968 KB
最終ジャッジ日時 2024-02-19 21:38:38
合計ジャッジ時間 4,894 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 1 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 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 39 ms
35,968 KB
testcase_16 AC 55 ms
35,968 KB
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 7 ms
6,676 KB
testcase_21 AC 11 ms
8,448 KB
testcase_22 AC 6 ms
6,676 KB
testcase_23 AC 9 ms
7,680 KB
testcase_24 AC 4 ms
6,676 KB
testcase_25 AC 4 ms
6,676 KB
testcase_26 AC 13 ms
8,704 KB
testcase_27 AC 4 ms
6,676 KB
testcase_28 AC 16 ms
14,592 KB
testcase_29 AC 32 ms
28,800 KB
testcase_30 AC 31 ms
24,576 KB
testcase_31 AC 26 ms
17,408 KB
testcase_32 AC 42 ms
28,928 KB
testcase_33 AC 48 ms
28,544 KB
testcase_34 AC 29 ms
17,792 KB
testcase_35 AC 27 ms
16,128 KB
testcase_36 AC 55 ms
32,512 KB
testcase_37 AC 71 ms
34,304 KB
testcase_38 AC 62 ms
30,976 KB
testcase_39 AC 70 ms
35,584 KB
testcase_40 AC 72 ms
33,792 KB
testcase_41 AC 47 ms
31,104 KB
testcase_42 AC 64 ms
32,256 KB
testcase_43 AC 67 ms
31,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=1<<30;

vector<int> dh={-1,-1,1,1},dw={-1,1,-1,1};

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int H,W;cin>>H>>W;
    vector<string> S(H);
    for(int i=0;i<H;i++){
        cin>>S[i];
    }
    
    vector<vector<vector<int>>> dp(4,vector<vector<int>>(H,vector<int>(W))),T;
    T=dp;
    
    for(int t=0;t<4;t++){
        if(t<2){
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    if(S[i][j]=='.') continue;
                    else{
                        int toh=i+dh[t],tow=j+dw[t];
                        if(0<=toh&&toh<H&&0<=tow&&tow<W){
                            dp[t][i][j]=dp[t][toh][tow]+1;
                        }else{
                            dp[t][i][j]=1;
                        }
                    }
                }
            }
        }else{
            for(int i=H-1;i>=0;i--){
                for(int j=0;j<W;j++){
                    if(S[i][j]=='.') continue;
                    else{
                        int toh=i+dh[t],tow=j+dw[t];
                        if(0<=toh&&toh<H&&0<=tow&&tow<W){
                            dp[t][i][j]=dp[t][toh][tow]+1;
                        }else{
                            dp[t][i][j]=1;
                        }
                    }
                }
            }
        }
    }
    
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            int can=INF;
            for(int k=0;k<4;k++) chmin(can,dp[k][i][j]);
            if(can>=2){
                for(int k=0;k<4;k++){
                    T[k][i][j]=can;
                    //cout<<T[k][i][j]<<" "<<i<<" "<<j<<endl;
                }
            }
        }
    }
    
    for(int t=0;t<4;t++){
        if(t>=2){
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    if(T[t][i][j]<=1) continue;
                    else{
                        int toh=i+dh[t],tow=j+dw[t];
                        chmax(T[t][toh][tow],T[t][i][j]-1);
                    }
                }
            }
        }else{
            for(int i=H-1;i>=0;i--){
                for(int j=0;j<W;j++){
                    if(T[t][i][j]<=1) continue;
                    else{
                        int toh=i+dh[t],tow=j+dw[t];
                        chmax(T[t][toh][tow],T[t][i][j]-1);
                    }
                }
            }
        }
    }
    
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            int f=0;
            for(int k=0;k<4;k++) if(T[k][i][j]) f=1;
            if(S[i][j]=='#'){
                if(f==0){
                    cout<<"No\n";
                    return 0;
                }
            }else{
                if(f){
                    cout<<"No\n";
                    return 0;
                }
            }
        }
    }
    
    cout<<"Yes\n";
}

0