結果

問題 No.2657 Falling Block Game
ユーザー SnowBeenDidingSnowBeenDiding
提出日時 2024-03-01 22:12:01
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 5,298 bytes
コンパイル時間 6,450 ms
コンパイル使用メモリ 324,880 KB
実行使用メモリ 12,396 KB
最終ジャッジ日時 2024-03-01 22:12:18
合計ジャッジ時間 16,302 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 67 ms
12,032 KB
testcase_05 AC 392 ms
12,396 KB
testcase_06 AC 302 ms
9,144 KB
testcase_07 AC 447 ms
12,396 KB
testcase_08 AC 214 ms
6,676 KB
testcase_09 AC 157 ms
12,032 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 156 ms
12,032 KB
testcase_31 WA -
testcase_32 AC 158 ms
12,032 KB
testcase_33 AC 157 ms
12,032 KB
testcase_34 WA -
testcase_35 AC 156 ms
12,032 KB
testcase_36 AC 157 ms
12,032 KB
testcase_37 WA -
testcase_38 AC 156 ms
12,032 KB
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/all>
#define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
using namespace std;
using namespace atcoder;

typedef long long ll;

const int inf = 1e9;

struct RMUQ {
    using S = ll;
    using F = ll;

   public:
    RMUQ() : RMUQ(0) {}
    RMUQ(int n) : RMUQ(std::vector<S>(n, e())) {}
    RMUQ(const std::vector<S>& v) : _n(int(v.size())) {
        log = ceil_pow2(_n);
        size = 1 << log;
        d = std::vector<S>(2 * size, e());
        lz = std::vector<F>(size, id());
        for (int i = 0; i < _n; i++) d[size + i] = v[i];
        for (int i = size - 1; i >= 1; i--) {
            update(i);
        }
    }

    void set(int p, S x) {
        assert(0 <= p && p < _n);
        p += size;
        for (int i = log; i >= 1; i--) push(p >> i);
        d[p] = x;
        for (int i = 1; i <= log; i++) update(p >> i);
    }
    S get(int p) {
        assert(0 <= p && p < _n);
        p += size;
        for (int i = log; i >= 1; i--) push(p >> i);
        return d[p];
    }
    S prod(int l, int r) {
        assert(0 <= l && l <= r && r <= _n);
        if (l == r) return e();
        l += size;
        r += size;
        for (int i = log; i >= 1; i--) {
            if (((l >> i) << i) != l) push(l >> i);
            if (((r >> i) << i) != r) push(r >> i);
        }
        S sml = e(), smr = e();
        while (l < r) {
            if (l & 1) sml = op(sml, d[l++]);
            if (r & 1) smr = op(d[--r], smr);
            l >>= 1;
            r >>= 1;
        }
        return op(sml, smr);
    }
    S all_prod() { return d[1]; }
    void apply(int p, F f) {
        assert(0 <= p && p < _n);
        p += size;
        for (int i = log; i >= 1; i--) push(p >> i);
        d[p] = mapping(f, d[p]);
        for (int i = 1; i <= log; i++) update(p >> i);
    }
    void apply(int l, int r, F f) {
        assert(0 <= l && l <= r && r <= _n);
        if (l == r) return;
        l += size;
        r += size;
        for (int i = log; i >= 1; i--) {
            if (((l >> i) << i) != l) push(l >> i);
            if (((r >> i) << i) != r) push((r - 1) >> i);
        }
        {
            int l2 = l, r2 = r;
            while (l < r) {
                if (l & 1) all_apply(l++, f);
                if (r & 1) all_apply(--r, f);
                l >>= 1;
                r >>= 1;
            }
            l = l2;
            r = r2;
        }
        for (int i = 1; i <= log; i++) {
            if (((l >> i) << i) != l) update(l >> i);
            if (((r >> i) << i) != r) update((r - 1) >> i);
        }
    }

    S op(S a, S b) { return min(a, b); }
    S e() { return 1e18; }
    S mapping(F f, S x) { return f != id() ? f : x; }
    F composition(F f, F g) { return f != id() ? f : g; }
    F id() { return -1e18; }

    int ceil_pow2(int n) {
        int x = 0;
        while ((1U << x) < (unsigned int)(n)) x++;
        return x;
    }
    ll operator[](int i) { return get(i); }
    void out() {
        for (int i = 0; i < _n; i++) cout << get(i) << " \n"[i == _n - 1];
    }
    void err() {
        for (int i = 0; i < _n; i++) cerr << get(i) << " \n"[i == _n - 1];
    }

   private:
    int _n, size, log;
    std::vector<S> d;
    std::vector<F> lz;
    void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
    void all_apply(int k, F f) {
        d[k] = mapping(f, d[k]);
        if (k < size) lz[k] = composition(f, lz[k]);
    }
    void push(int k) {
        all_apply(2 * k, lz[k]);
        all_apply(2 * k + 1, lz[k]);
        lz[k] = id();
    }
};

vector<int> f(vector<int> a, string s) {
    int n = a.size();
    vector<int> ret(n);
    RMUQ rsuq(n);
    vector<pair<int, int>> ord;
    rep(i, 0, n) ord.emplace_back(a[i], i);
    sort(ord.rbegin(), ord.rend());
    rep(i, 0, n) {
        int idx = ord[i].second;
        if (s[idx] == '#') continue;
        int l = max(0, idx - a[idx]), r = min(n, idx + a[idx] + 1);
        rsuq.apply(l, r, a[idx]);
    }
    rep(i, 0, n) {
        ll nw = rsuq.get(i);
        if (nw >= 1e18 / 2)
            ret[i] = inf;
        else
            ret[i] = nw;
    }
    vector<int> l(n, inf), r(n, inf);
    rep(i, 1, n) {
        if (ret[i] >= inf / 2) {
            l[i] = min(ret[i - 1] + 1, l[i - 1] + 1);
        }
    }
    for (int i = n - 2; i >= 0; i--) {
        if (ret[i] >= inf / 2) {
            r[i] = min(ret[i + 1] + 1, r[i + 1] + 1);
        }
    }
    rep(i, 0, n) ret[i] = min({ret[i], l[i], r[i]});
    return ret;
}

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, 0, h) cin >> s[i];
    vector<vector<int>> dp(h, vector<int>(w, 0));
    for (int i = h - 2; i >= 0; i--) {
        auto l = f(dp[i + 1], s[i]);
        reverse(dp[i + 1].begin(), dp[i + 1].end());
        auto r = f(dp[i + 1], s[i]);
        reverse(r.begin(), r.end());
        reverse(dp[i + 1].begin(), dp[i + 1].end());
        rep(j, 0, w) {
            dp[i][j] = min(l[j], r[j]);
            if (s[i][j] == '#') dp[i][j] = inf;
        }
    }
    // rep(i, 0, h) {
    //     rep(j, 0, w) {
    //         if (dp[i][j] >= inf / 2)
    //             cout << "x ";
    //         else
    //             cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    rep(i, 0, w) cout << dp[0][i] << endl;
}
0