結果

問題 No.2657 Falling Block Game
ユーザー ゼットゼット
提出日時 2024-03-01 22:54:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,069 ms / 2,000 ms
コード長 3,695 bytes
コンパイル時間 1,126 ms
コンパイル使用メモリ 97,968 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-01 22:54:31
合計ジャッジ時間 12,129 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 22 ms
6,676 KB
testcase_05 AC 1,003 ms
6,676 KB
testcase_06 AC 474 ms
6,676 KB
testcase_07 AC 1,069 ms
6,676 KB
testcase_08 AC 327 ms
6,676 KB
testcase_09 AC 52 ms
6,676 KB
testcase_10 AC 474 ms
6,676 KB
testcase_11 AC 477 ms
6,676 KB
testcase_12 AC 480 ms
6,676 KB
testcase_13 AC 480 ms
6,676 KB
testcase_14 AC 474 ms
6,676 KB
testcase_15 AC 475 ms
6,676 KB
testcase_16 AC 476 ms
6,676 KB
testcase_17 AC 476 ms
6,676 KB
testcase_18 AC 479 ms
6,676 KB
testcase_19 AC 477 ms
6,676 KB
testcase_20 AC 114 ms
6,676 KB
testcase_21 AC 114 ms
6,676 KB
testcase_22 AC 114 ms
6,676 KB
testcase_23 AC 114 ms
6,676 KB
testcase_24 AC 114 ms
6,676 KB
testcase_25 AC 114 ms
6,676 KB
testcase_26 AC 113 ms
6,676 KB
testcase_27 AC 115 ms
6,676 KB
testcase_28 AC 113 ms
6,676 KB
testcase_29 AC 114 ms
6,676 KB
testcase_30 AC 53 ms
6,676 KB
testcase_31 AC 53 ms
6,676 KB
testcase_32 AC 53 ms
6,676 KB
testcase_33 AC 53 ms
6,676 KB
testcase_34 AC 53 ms
6,676 KB
testcase_35 AC 55 ms
6,676 KB
testcase_36 AC 53 ms
6,676 KB
testcase_37 AC 53 ms
6,676 KB
testcase_38 AC 52 ms
6,676 KB
testcase_39 AC 50 ms
6,676 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In member function 'int segtree::query(int, int)':
main.cpp:34:21: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+10' to '2147483647' [-Woverflow]
   34 |         int score = 1e10;
      |                     ^~~~

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

class segtree {
private:
    int size;
    vector<int> dat;

public:
    segtree(int n) {
        size = 1;
        while (size < n) {
            size *= 2;
        }
        dat.assign(size * 2, 0);
    }

    void update(int x, int a) {
        x += size;
        dat[x] = a;
        while (x > 1) {
            x /= 2;
            dat[x] = min(dat[2 * x], dat[2 * x + 1]);
        }
    }

    int query(int u, int v) {
        u += size;
        v += size;
        int score = 1e10;
        while (u < v) {
            if (u & 1) {
                score = min(score, dat[u]);
                u++;
            }
            if (v & 1) {
                v--;
                score = min(score, dat[v]);
            }
            u /= 2;
            v /= 2;
        }
        return score;
    }
};

class segtreemax {
private:
    int size;
    vector<int> dat;

public:
    segtreemax(int n) {
        size = 1;
        while (size < n) {
            size *= 2;
        }
        dat.assign(size * 2, 0);
    }

    void update(int x, int a) {
        x += size;
        dat[x] = a;
        while (x > 1) {
            x /= 2;
            dat[x] = max(dat[2 * x], dat[2 * x + 1]);
        }
    }

    int query(int u, int v) {
        u += size;
        v += size;
        int score = 0;
        while (u < v) {
            if (u & 1) {
                score = max(score, dat[u]);
                u++;
            }
            if (v & 1) {
                v--;
                score = max(score, dat[v]);
            }
            u /= 2;
            v /= 2;
        }
        return score;
    }
};

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> A(H);
    for (int i = 0; i < H; ++i) {
        cin >> A[i];
    }
    vector<int> dp(W, 0);
    segtree Z(W);
    for (int i = H - 2; i >= 0; --i) {
        vector<int> dp2(W, 1e8);
        vector<int> L;
        L.push_back(-1);
        for (int j = 0; j < W; ++j) {
            if (A[i][j] == '#') {
                L.push_back(j);
            }
        }
        L.push_back(W);
        for (int j = 0; j < W; ++j) {
            if (A[i][j] == '#') {
                continue;
            }
            int pos = lower_bound(L.begin(), L.end(), j) - L.begin();
            int a = L[pos - 1];
            int b = L[pos];
            int ans = 1e8;
            int l = 0, r = W - 1;
            while (true) {
                if (l == r) {
                    break;
                }
                int m = (l + r) / 2;
                int y = j + m;
                if (y >= b) {
                    y = b - 1;
                }
                int score = Z.query(j, y + 1);
                if (score <= m) {
                    r = m;
                } else {
                    l = m + 1;
                }
            }
            ans = min(ans, l);
            l = 0;
            r = W - 1;
            while (true) {
                if (l == r) {
                    break;
                }
                int m = (l + r) / 2;
                int y = j - m;
                if (y <= a) {
                    y = a + 1;
                }
                int score = Z.query(y, j + 1);
                if (score <= m) {
                    r = m;
                } else {
                    l = m + 1;
                }
            }
            ans = min(ans, l);
            dp2[j] = ans;
        }
        dp = dp2;
        for (int j = 0; j < W; ++j) {
            Z.update(j, dp[j]);
        }
    }
    for (int i = 0; i < W; ++i) {
        cout << dp[i] << endl;
    }
    return 0;
}
0