結果

問題 No.2657 Falling Block Game
ユーザー sotanishysotanishy
提出日時 2024-03-01 22:12:29
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 179 ms / 2,000 ms
コード長 2,315 bytes
コンパイル時間 3,403 ms
コンパイル使用メモリ 258,616 KB
実行使用メモリ 12,304 KB
最終ジャッジ日時 2024-03-01 22:12:40
合計ジャッジ時間 7,669 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 24 ms
6,676 KB
testcase_05 AC 179 ms
12,304 KB
testcase_06 AC 128 ms
7,944 KB
testcase_07 AC 94 ms
10,008 KB
testcase_08 AC 72 ms
6,676 KB
testcase_09 AC 75 ms
6,676 KB
testcase_10 AC 73 ms
11,792 KB
testcase_11 AC 72 ms
11,792 KB
testcase_12 AC 74 ms
11,792 KB
testcase_13 AC 73 ms
11,792 KB
testcase_14 AC 74 ms
11,792 KB
testcase_15 AC 74 ms
11,792 KB
testcase_16 AC 73 ms
11,792 KB
testcase_17 AC 73 ms
11,792 KB
testcase_18 AC 74 ms
11,792 KB
testcase_19 AC 77 ms
11,792 KB
testcase_20 AC 74 ms
6,676 KB
testcase_21 AC 74 ms
6,676 KB
testcase_22 AC 76 ms
6,676 KB
testcase_23 AC 76 ms
6,676 KB
testcase_24 AC 77 ms
6,676 KB
testcase_25 AC 76 ms
6,676 KB
testcase_26 AC 76 ms
6,676 KB
testcase_27 AC 75 ms
6,676 KB
testcase_28 AC 75 ms
6,676 KB
testcase_29 AC 75 ms
6,676 KB
testcase_30 AC 69 ms
6,676 KB
testcase_31 AC 69 ms
6,676 KB
testcase_32 AC 70 ms
6,676 KB
testcase_33 AC 70 ms
6,676 KB
testcase_34 AC 69 ms
6,676 KB
testcase_35 AC 69 ms
6,676 KB
testcase_36 AC 69 ms
6,676 KB
testcase_37 AC 69 ms
6,676 KB
testcase_38 AC 69 ms
6,676 KB
testcase_39 AC 69 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i)
#define revrep(i, t, s) for (int i = (int)(t)-1; i >= (int)(s); --i)
#define all(x) begin(x), end(x)
template <typename T>
bool chmax(T& a, const T& b) {
    return a < b ? (a = b, 1) : 0;
}
template <typename T>
bool chmin(T& a, const T& b) {
    return a > b ? (a = b, 1) : 0;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for (auto& row : S) cin >> row;
    vector<int> dp(W, 0);
    const int INF = 1e9;
    revrep(i, H, 0) {
        vector<int> ndp(W, INF);

        vector<vector<int>> diff(W);
        multiset<int> st;
        int left = -1;
        int reset = -1;
        rep(j, 0, W) {
            if (S[i][j] == '#') {
                st.clear();
                left = -1;
                reset = j;
                continue;
            }

            st.insert(dp[j]);
            if (j + dp[j] < W) {
                diff[j + dp[j]].push_back(j);
            }

            if (!st.empty()) {
                chmin(ndp[j], *st.begin());
            }
            if (left != -1) {
                chmin(ndp[j], j - left);
            }

            for (int k : diff[j]) {
                if (k <= reset) continue;
                st.erase(st.find(dp[k]));
                chmax(left, k);
            }
            diff[j].clear();
        }

        st.clear();
        int right = W;
        reset = W;
        revrep(j, W, 0) {
            if (S[i][j] == '#') {
                st.clear();
                right = W;
                reset = j;
                continue;
            }

            st.insert(dp[j]);
            if (j - dp[j] >= 0) {
                diff[j - dp[j]].push_back(j);
            }

            if (!st.empty()) {
                chmin(ndp[j], *st.begin());
            }
            if (right != W) {
                chmin(ndp[j], right - j);
            }

            for (int k : diff[j]) {
                if (reset <= k) continue;
                st.erase(st.find(dp[k]));
                chmin(right, k);
            }
        }

        dp.swap(ndp);
    }
    rep(j, 0, W) cout << dp[j] << "\n";
}
0