結果

問題 No.2641 draw X
ユーザー kokosei
提出日時 2024-02-19 23:13:32
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 2,372 bytes
コンパイル時間 3,531 ms
コンパイル使用メモリ 271,336 KB
実行使用メモリ 130,948 KB
最終ジャッジ日時 2024-09-29 02:55:02
合計ジャッジ時間 14,755 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34 TLE * 1 -- * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int H, W;
vector<string> S;
bool inside(int x, int y){
    return 0 <= x && x < H && 0 <= y && y < W;
}
int dx[4] = {1, 1, -1, -1};
int dy[4] = {1, -1, -1, 1};
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> H >> W;
    S.resize(H);
    auto vtd = vector<vector<bool>>(H, vector<bool>(W));
    auto power = vector<vector<vector<int>>>(H, vector<vector<int>>(W, vector<int>(4, -1)));
    for(int i = 0;i < H;i++)cin >> S[i];
    using pp = pair<int, tuple<int, int, int>>;
    priority_queue<pp> que;
    for(int i = 0;i < H;i++){
        for(int j = 0;j < W;j++){
            if(S[i][j] == '.')continue;
            {
                int c = 0;
                for(int d = 0;d < 4;d++){
                    int x = i + dx[d], y = j + dy[d];
                    if(!inside(x, y))continue;
                    if(S[x][y] == '#')c++;
                }
                if(c != 4)continue;
            }
            int l = 0, r = max(H, W) + 1;
            while(r - l > 1){
                int m = (l + r) / 2;
                int c = 0;
                for(int d = 0;d < 4;d++){
                    int x = i + dx[d] * m, y = j + dy[d] * m;
                    if(!inside(x, y))continue;
                    if(S[x][y] == '#')c++;
                }
                if(c == 4)l = m;
                else r = m;
            }
            if(l > 0){
                for(int d = 0;d < 4;d++){
                    power[i][j][d] = l;
                    que.push({l, {i, j, d}});
                }
            }
        }
    }
    while(que.size()){
        auto [p, v] = que.top(); que.pop();
        auto [x, y, d] = v;
        if(p < power[x][y][d])continue;
        int nx = x + dx[d], ny = y + dy[d];
        if(!inside(nx, ny))continue;
        if(S[nx][ny] == '.')continue;
        if(power[nx][ny][d] < p - 1){
            power[nx][ny][d] = p - 1;
            if(p - 1 > 0)que.push({p - 1, {nx, ny, d}});
        }
    }
    bool f = true;
    for(int i = 0;i < H;i++){
        for(int j = 0;j < W;j++){
            if(S[i][j] != '#')continue;
            bool g = false;
            for(int d = 0;d < 4;d++){
                if(power[i][j][d] != -1)g = true;
            }
            f &= g;
        }
    }
    cout << (f ? "Yes\n" : "No\n");
    return 0;
}
0