結果

問題 No.2641 draw X
ユーザー GOTKAKOGOTKAKO
提出日時 2024-02-19 22:43:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 2,506 bytes
コンパイル時間 2,588 ms
コンパイル使用メモリ 223,904 KB
実行使用メモリ 24,320 KB
最終ジャッジ日時 2024-02-19 22:43:52
合計ジャッジ時間 5,370 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 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 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 35 ms
24,320 KB
testcase_16 AC 73 ms
24,320 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 12 ms
6,912 KB
testcase_22 AC 6 ms
6,676 KB
testcase_23 AC 10 ms
6,676 KB
testcase_24 AC 4 ms
6,676 KB
testcase_25 AC 4 ms
6,676 KB
testcase_26 AC 13 ms
7,040 KB
testcase_27 AC 5 ms
6,676 KB
testcase_28 AC 20 ms
10,624 KB
testcase_29 AC 32 ms
19,712 KB
testcase_30 AC 34 ms
17,024 KB
testcase_31 AC 31 ms
12,416 KB
testcase_32 AC 47 ms
19,840 KB
testcase_33 AC 56 ms
19,584 KB
testcase_34 AC 36 ms
12,672 KB
testcase_35 AC 30 ms
11,520 KB
testcase_36 AC 59 ms
22,400 KB
testcase_37 AC 71 ms
23,552 KB
testcase_38 AC 65 ms
21,376 KB
testcase_39 AC 73 ms
24,320 KB
testcase_40 AC 70 ms
22,912 KB
testcase_41 AC 50 ms
21,376 KB
testcase_42 AC 67 ms
22,272 KB
testcase_43 AC 68 ms
21,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

    int H,W; cin >> H >> W;
    vector<string> S(H);
    for(auto &s : S) cin >> s;

    vector UL(H,vector<int>(W)),UR = UL,DL = UL,DR = UL;
    for(int i=0; i<H-1; i++) for(int k=0; k<W; k++){
        if(S.at(i).at(k) == '.') continue;
        if(k) DL.at(i+1).at(k-1) = DL.at(i).at(k)+1;
        if(k != W-1) DR.at(i+1).at(k+1) = DR.at(i).at(k)+1;
    }
    for(int i=H-1; i>0; i--) for(int k=0; k<W; k++){
        if(S.at(i).at(k) == '.') continue;
        if(k) UL.at(i-1).at(k-1) = UL.at(i).at(k)+1;
        if(k != W-1) UR.at(i-1).at(k+1) = UR.at(i).at(k)+1;
    }

    vector<vector<int>> R(H,vector<int>(W));
    for(int i=0; i<H; i++) for(int k=0; k<W; k++){
        if(S.at(i).at(k) == '.') continue;
        R.at(i).at(k) = min({UR[i][k],UL[i][k],DR[i][k],DL[i][k]});
    }

    vector<vector<bool>> ok(H,vector<bool>(W));
    for(int i=0; i<H; i++) for(int k=0; k<W; k++){
        if(i-1 >= 0 && k-1 >= 0) continue;
        int x = i,y = k,r = -1;
        stack<pair<int,int>> st;
        while(x < H && y < W){
            if(S.at(x).at(y) == '.'){x++,y++; continue;}
            if(R.at(x).at(y) != 0) r = max(r,R.at(x).at(y));
            if(r == -1) st.push({x,y}); 
            else{
                ok.at(x).at(y) = true;
                while(st.size()){
                    auto [bx,by] = st.top();
                    if(x-bx <= r) ok.at(bx).at(by) = true,st.pop();
                    else break;
                }
                r--;
            }
            x++; y++;
        }
    }
    for(int i=0; i<H; i++) for(int k=0; k<W; k++){
        if(i-1 >= 0 && k+1 < W) continue;
        int x = i,y = k,r = -1;
        stack<pair<int,int>> st;
        while(x < H && y >= 0){
            if(S.at(x).at(y) == '.'){x++,y--; continue;}
            if(R.at(x).at(y) != 0) r = max(r,R.at(x).at(y));
            if(r == -1) st.push({x,y}); 
            else{
                ok.at(x).at(y) = true;
                while(st.size()){
                    auto [bx,by] = st.top();
                    if(x-bx <= r) ok.at(bx).at(by) = true,st.pop();
                    else break;
                }
                r--;
            }
            x++; y--;
        }
    }

    bool yes = true;
    for(int i=0; i<H; i++) for(int k=0; k<W; k++) if(S.at(i).at(k) == '#' && !ok.at(i).at(k)) yes = false;
    if(yes) cout << "Yes" << endl;
    else cout << "No" << endl; 
}
0