結果

問題 No.2641 draw X
ユーザー pitPpitP
提出日時 2024-02-19 23:19:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 5,881 bytes
コンパイル時間 4,534 ms
コンパイル使用メモリ 274,952 KB
実行使用メモリ 75,136 KB
最終ジャッジ日時 2024-09-29 03:01:45
合計ジャッジ時間 9,662 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,816 KB
testcase_03 AC 2 ms
6,820 KB
testcase_04 AC 2 ms
6,816 KB
testcase_05 AC 2 ms
6,816 KB
testcase_06 AC 2 ms
6,820 KB
testcase_07 AC 2 ms
6,816 KB
testcase_08 WA -
testcase_09 AC 2 ms
6,820 KB
testcase_10 AC 2 ms
6,820 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 2 ms
6,820 KB
testcase_14 AC 2 ms
6,816 KB
testcase_15 AC 73 ms
75,136 KB
testcase_16 AC 73 ms
75,008 KB
testcase_17 AC 2 ms
6,820 KB
testcase_18 AC 1 ms
6,820 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 AC 74 ms
73,984 KB
testcase_40 RE -
testcase_41 AC 61 ms
64,128 KB
testcase_42 RE -
testcase_43 AC 67 ms
65,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
istream &operator>>(istream &is, modint &a) { long long v; is >> v; a = v; return is; }
ostream &operator<<(ostream &os, const modint &a) { return os << a.val(); }
istream &operator>>(istream &is, modint998244353 &a) { long long v; is >> v; a = v; return is; }
ostream &operator<<(ostream &os, const modint998244353 &a) { return os << a.val(); }
istream &operator>>(istream &is, modint1000000007 &a) { long long v; is >> v; a = v; return is; }
ostream &operator<<(ostream &os, const modint1000000007 &a) { return os << a.val(); } 

typedef long long ll;
typedef vector<vector<int>> Graph;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define FOR(i,l,r) for (int i = l;i < (int)(r); i++)
#define rep(i,n) for (int i = 0;i < (int)(n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define my_sort(x) sort(x.begin(), x.end())
#define my_max(x) *max_element(all(x))
#define my_min(x) *min_element(all(x))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<62) - 1;
const int MOD = 998244353;
const int MOD2 = 1e9+7;
const double PI = acos(-1);
vector<int> di = {1,0,-1,0};
vector<int> dj = {0,1,0,-1};

#ifdef LOCAL
#  include <debug_print.hpp>
#  define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#  define debug(...) (static_cast<void>(0))
#endif

struct cumulative_sum_2d{
    int H,W;
    vector<vector<ll>> val;
    vector<vector<ll>> wa;
    cumulative_sum_2d(int H_input, int W_input){init(H_input,W_input);}
    void init(int H_input, int W_input){
        H = H_input;
        W = W_input;
        val.assign(H,vector<ll>(W,0ll));
        wa.assign(H+1,vector<ll>(W+1,0ll));
    }
    void set(int i, int j, ll value){
        val[i][j] = value;
    }
    void add(int i, int j, ll value){
        val[i][j] += value;
    }
    void build(){
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                wa[i+1][j+1] = wa[i][j+1] + wa[i+1][j] - wa[i][j] + val[i][j];
            }
        }
    }
    // [i1, i2) x [j1, j2)
    ll query(int i1,int j1, int i2, int j2){
        return wa[i2][j2] - wa[i2][j1] - wa[i1][j2] + wa[i1][j1];
    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int H, W; cin >> H >> W;
    vector<string> S(H);
    rep(i,H) cin >> S[i];
    vector A(2 * H, vector<int>(2 * W));
    auto id = [&](int i, int j){
        return make_pair(i + j, i - j + W);
    };
    rep(i,H)rep(j,W){
        auto [ni, nj] = id(i, j);
        if(S[i][j]=='#'){
            A[ni][nj] = 1;
        }
    }
    debug(A);

    vector even(H, vector<ll>(W));
    vector odd(H, vector<ll>(W));
    rep(i,H)rep(j,W) {
        even[i][j] = A[2 * i][2 * j + 1];
        odd[i][j] = A[2 * i + 1][2 * j];
    }
    debug(even, odd);

    cumulative_sum_2d e_acc(H, W);
    cumulative_sum_2d o_acc(H, W);
    rep(i,H)rep(j,W){
        e_acc.add(i,j,even[i][j]);
        o_acc.add(i,j,odd[i][j]);
    }
    e_acc.build();
    o_acc.build();

    vector e_imos(H + 1, vector<int>(W + 1));
    vector o_imos(H + 1, vector<int>(W + 1));
    rep(i,H)rep(j,W){
        if(even[i][j]){
            int ok = 0, ng = 1 << 30;
            while(abs(ok - ng) > 1){
                int mid = (ok + ng) / 2;
                bool is_ok = true;
                rep(d,4){
                    int ni = i + di[d] * mid;
                    int nj = j + dj[d] * mid;
                    if(ni < 0 || ni >= H || nj < 0 || nj >= W){
                        is_ok = false;
                        continue;
                    }
                    is_ok &= e_acc.query(min(i,ni),min(j,nj),max(i,ni) + 1,max(j,nj) + 1) == mid + 1;
                }
                if(is_ok) ok = mid;
                else ng = mid;
            }
            if(ok == 0)continue;
            debug(ok, i, j);
            e_imos[i - ok][j]++;
            e_imos[i - ok][j + 1]--;
            e_imos[i + ok + 1][j]--;
            e_imos[i + ok + 1][j + 1]++;
            e_imos[i][j - ok]++;
            e_imos[i + 1][j - ok]--;
            e_imos[i][j + ok + 1]--;
            e_imos[i + 1][j + ok + 1]++;
        }
        if(odd[i][j]){
            int ok = 0, ng = 1 << 30;
            while(abs(ok - ng) > 1){
                int mid = (ok + ng) / 2;
                bool is_ok = true;
                rep(d,4){
                    int ni = i + di[d] * mid;
                    int nj = j + dj[d] * mid;
                    if(ni < 0 || ni >= H || nj < 0 || nj >= W){
                        is_ok = false;
                        continue;
                    }
                    is_ok &= o_acc.query(min(i,ni),min(j,nj),max(i,ni) + 1,max(j,nj) + 1) == mid + 1;
                }
                if(is_ok) ok = mid;
                else ng = mid;
            }
            if(ok == 0)continue;
            debug(ok, i, j);
            o_imos[i - ok][j]++;
            o_imos[i - ok][j + 1]--;
            o_imos[i + ok + 1][j]--;
            o_imos[i + ok + 1][j + 1]++;
            o_imos[i][j - ok]++;
            o_imos[i + 1][j - ok]--;
            o_imos[i][j + ok + 1]--;
            o_imos[i + 1][j + ok + 1]++;
        }
    }
    rep(i,H)rep(j,W){
        e_imos[i + 1][j] += e_imos[i][j];
        o_imos[i + 1][j] += o_imos[i][j];
    }
    rep(i,H)rep(j,W){
        e_imos[i][j + 1] += e_imos[i][j];
        o_imos[i][j + 1] += o_imos[i][j];
    }
    debug(e_imos, o_imos);

    bool f = true;
    rep(i,H)rep(j,W){
        if(even[i][j] > 0){
            f &= e_imos[i][j] > 0;
        }
        if(odd[i][j] > 0){
            f &= o_imos[i][j] > 0;
        }
    }
    cout << (f ? "Yes" : "No") << endl;
}
0