結果

問題 No.2641 draw X
ユーザー noya2noya2
提出日時 2024-02-13 21:02:00
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 167 ms / 2,000 ms
コード長 2,379 bytes
コンパイル時間 6,366 ms
コンパイル使用メモリ 257,756 KB
実行使用メモリ 16,424 KB
最終ジャッジ日時 2024-02-13 21:02:12
合計ジャッジ時間 7,878 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 2 ms
6,548 KB
testcase_07 AC 1 ms
6,548 KB
testcase_08 AC 2 ms
6,548 KB
testcase_09 AC 2 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 2 ms
6,548 KB
testcase_12 AC 2 ms
6,548 KB
testcase_13 AC 2 ms
6,548 KB
testcase_14 AC 2 ms
6,548 KB
testcase_15 AC 142 ms
16,424 KB
testcase_16 AC 152 ms
16,424 KB
testcase_17 AC 2 ms
6,548 KB
testcase_18 AC 2 ms
6,548 KB
testcase_19 AC 2 ms
6,548 KB
testcase_20 AC 12 ms
6,548 KB
testcase_21 AC 24 ms
6,548 KB
testcase_22 AC 10 ms
6,548 KB
testcase_23 AC 19 ms
6,548 KB
testcase_24 AC 8 ms
6,548 KB
testcase_25 AC 7 ms
6,548 KB
testcase_26 AC 26 ms
6,548 KB
testcase_27 AC 7 ms
6,548 KB
testcase_28 AC 57 ms
9,640 KB
testcase_29 AC 116 ms
14,380 KB
testcase_30 AC 106 ms
12,436 KB
testcase_31 AC 71 ms
9,652 KB
testcase_32 AC 135 ms
14,416 KB
testcase_33 AC 132 ms
14,552 KB
testcase_34 AC 79 ms
11,676 KB
testcase_35 AC 64 ms
9,244 KB
testcase_36 AC 142 ms
15,112 KB
testcase_37 AC 164 ms
15,836 KB
testcase_38 AC 144 ms
14,452 KB
testcase_39 AC 167 ms
16,300 KB
testcase_40 AC 153 ms
15,576 KB
testcase_41 AC 130 ms
14,528 KB
testcase_42 AC 152 ms
15,032 KB
testcase_43 AC 146 ms
14,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template<typename T>
bool chmax(T &a, const T &b){
    if (a >= b){
        return false;
    }
    a = b;
    return true;
}
template<typename T>
bool chmin(T &a, const T &b){
    if (a <= b){
        return false;
    }
    a = b;
    return true;
}

vector<vector<int>> max_ur(vector<vector<char>> &a){
    int h = a.size();
    int w = a[0].size();
    vector<vector<int>> ans(h,vector<int>(w,0));
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++){
        if (a[i][j] == '#'){
            ans[i][j] = 1;
            if (i > 0 && j > 0){
                chmax(ans[i][j],ans[i-1][j-1]+1);
            }
        }
    }
    return ans;
}

template<typename T>
void rotated(vector<vector<T>> &a){
    int h = a.size();
    int w = a[0].size();
    vector<vector<T>> b(w,vector<T>(h));
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++){
        b[j][h-1-i] = a[i][j];
    }
    swap(a,b);
}

int main(){
    int h, w; cin >> h >> w;
    vector<vector<char>> a(h,vector<char>(w));
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++){
        cin >> a[i][j];
    }
    vector<vector<int>> dp(h,vector<int>(w,h+w));
    for (int t = 0; t < 4; t++){
        auto ep = max_ur(a);
        for (int s = 0; s < 4-t; s++){
            rotated(ep);
        }
        for (int i = 0; i < h; i++) for (int j = 0; j < w; j++){
            chmin(dp[i][j],ep[i][j]);
        }
        rotated(a);
    }
    vector<vector<int>> imosm(h,vector<int>(w,0)), imosp(h,vector<int>(w,0));
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++){
        if (dp[i][j] <= 1) continue;
        int r = dp[i][j]-1;
        imosm[i-r][j-r]++;
        if (i+r+1 < h && j+r+1 < w){
            imosm[i+r+1][j+r+1]--;
        }
        imosp[i-r][j+r]++;
        if (i+r+1 < h && j-r-1 >= 0){
            imosp[i+r+1][j-r-1]--;
        }
    }
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++){
        if (i+1 < h && j+1 < w){
            imosm[i+1][j+1] += imosm[i][j];
        }
        if (i+1 < h && j-1 >= 0){
            imosp[i+1][j-1] += imosp[i][j];
        }
    }
    bool ans = true;
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++){
        if (a[i][j] == '#' && imosm[i][j]+imosp[i][j] == 0){
            ans = false;
            break;
        }
    }
    cout << (ans ? "Yes" : "No") << endl;
}
0