結果

問題 No.2641 draw X
ユーザー t98slidert98slider
提出日時 2024-03-10 20:55:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 614 ms / 2,000 ms
コード長 2,232 bytes
コンパイル時間 2,401 ms
コンパイル使用メモリ 213,756 KB
実行使用メモリ 113,920 KB
最終ジャッジ日時 2024-03-10 20:55:58
合計ジャッジ時間 9,532 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 1 ms
6,548 KB
testcase_07 AC 2 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 203 ms
113,792 KB
testcase_16 AC 488 ms
113,920 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 22 ms
10,752 KB
testcase_21 AC 46 ms
20,480 KB
testcase_22 AC 24 ms
10,240 KB
testcase_23 AC 37 ms
17,920 KB
testcase_24 AC 12 ms
9,344 KB
testcase_25 AC 12 ms
8,320 KB
testcase_26 AC 59 ms
21,248 KB
testcase_27 AC 14 ms
7,552 KB
testcase_28 AC 90 ms
42,852 KB
testcase_29 AC 172 ms
90,636 KB
testcase_30 AC 169 ms
75,952 KB
testcase_31 AC 141 ms
51,628 KB
testcase_32 AC 222 ms
90,808 KB
testcase_33 AC 359 ms
89,976 KB
testcase_34 AC 154 ms
53,996 KB
testcase_35 AC 182 ms
47,184 KB
testcase_36 AC 279 ms
102,016 KB
testcase_37 AC 568 ms
108,288 KB
testcase_38 AC 308 ms
96,640 KB
testcase_39 AC 330 ms
112,512 KB
testcase_40 AC 614 ms
106,496 KB
testcase_41 AC 249 ms
97,024 KB
testcase_42 AC 352 ms
101,248 KB
testcase_43 AC 340 ms
98,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template<class T> istream& operator >> (istream& is, vector<T>& vec) {
    for(T& x : vec) is >> x;
    return is;
}

template<class T> ostream& operator << (ostream& os, const vector<T>& vec) {
    if(vec.empty()) return os;
    os << vec[0];
    for(auto it = vec.begin(); ++it != vec.end(); ) os << ' ' << *it;
    return os;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w;
    cin >> h >> w;
    vector<string> A(h);
    cin >> A;
    vector dp(h, vector(w, vector<int>(4, -1)));
    vector dp2(h, vector(w, vector<int>(4)));
    auto rec = [&](auto rec, int y, int x, int ds) -> int {
        if(y < 0 || x < 0 || y >= h || x >= w) return 0;
        if(dp[y][x][ds] != -1) return dp[y][x][ds];
        if(A[y][x] == '.') return dp[y][x][ds] = 0;
        return dp[y][x][ds] = 1 + rec(rec, y + (ds & 1 ? 1 : -1), x + (ds & 2 ? 1 : -1), ds);
    };
    for(int y = 0; y < h; y++){
        for(int x = 0; x < w; x++){
            if(A[y][x] == '.') continue;
            int ans = 1 << 30;
            for(int s = 0; s < 4; s++){
                ans = min(ans, rec(rec, y, x, s));
            }
            if(ans >= 2) fill(dp2[y][x].begin(), dp2[y][x].end(), ans);
        }
    }

    for(int s = 0; s < 4; s++){
        int dx = s & 2 ? 1 : -1;
        if(s & 1){
            for(int y = 0; y + 1 < h; y++){
                for(int x = 0; x < w; x++){
                    if(x + dx < 0 || x + dx >= w) continue;
                    dp2[y + 1][x + dx][s] = max(dp2[y + 1][x + dx][s], dp2[y][x][s] - 1);
                }
            }
        }else{
            for(int y = h - 1; y >= 1; y--){
                for(int x = 0; x < w; x++){
                    if(x + dx < 0 || x + dx >= w) continue;
                    dp2[y - 1][x + dx][s] = max(dp2[y - 1][x + dx][s], dp2[y][x][s] - 1);
                }
            }
        }
    }
    for(int y = 0; y < h; y++){
        for(int x = 0; x < w; x++){
            if(A[y][x] == '.') continue;
            if(accumulate(dp2[y][x].begin(), dp2[y][x].end(), 0) == 0){
                cout << "No\n";
                return 0;
            }
        }
    }
    cout << "Yes\n";
}
0