結果

問題 No.2657 Falling Block Game
ユーザー ぷらぷら
提出日時 2024-03-01 21:43:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 3,342 bytes
コンパイル時間 1,784 ms
コンパイル使用メモリ 150,700 KB
実行使用メモリ 20,732 KB
最終ジャッジ日時 2024-03-01 21:43:10
合計ジャッジ時間 6,492 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 32 ms
6,548 KB
testcase_05 AC 126 ms
20,732 KB
testcase_06 AC 94 ms
11,904 KB
testcase_07 AC 125 ms
20,732 KB
testcase_08 AC 50 ms
6,548 KB
testcase_09 AC 54 ms
6,548 KB
testcase_10 AC 93 ms
20,732 KB
testcase_11 AC 92 ms
20,732 KB
testcase_12 AC 91 ms
20,732 KB
testcase_13 AC 92 ms
20,732 KB
testcase_14 AC 93 ms
20,732 KB
testcase_15 AC 94 ms
20,732 KB
testcase_16 AC 92 ms
20,732 KB
testcase_17 AC 93 ms
20,732 KB
testcase_18 AC 96 ms
20,732 KB
testcase_19 AC 91 ms
20,732 KB
testcase_20 AC 52 ms
6,548 KB
testcase_21 AC 52 ms
6,548 KB
testcase_22 AC 52 ms
6,548 KB
testcase_23 AC 53 ms
6,548 KB
testcase_24 AC 52 ms
6,548 KB
testcase_25 AC 53 ms
6,548 KB
testcase_26 AC 54 ms
6,548 KB
testcase_27 AC 53 ms
6,548 KB
testcase_28 AC 52 ms
6,548 KB
testcase_29 AC 52 ms
6,548 KB
testcase_30 AC 58 ms
6,548 KB
testcase_31 AC 59 ms
6,548 KB
testcase_32 AC 59 ms
6,548 KB
testcase_33 AC 60 ms
6,548 KB
testcase_34 AC 60 ms
6,548 KB
testcase_35 AC 58 ms
6,548 KB
testcase_36 AC 58 ms
6,548 KB
testcase_37 AC 58 ms
6,548 KB
testcase_38 AC 58 ms
6,548 KB
testcase_39 AC 57 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

int inf = 1001001001;

struct SparseTable {//質問 l = r で壊れる
    vector<int>A;
    vector<int>log_table;
    vector<vector<int>>table;
    SparseTable(int n,vector<int> a) {
        A = a;
        int k = 0;
        int tmp = 1;
        while(tmp <= n) {
            k++;
            tmp *= 2;
        }
        log_table.resize(n+1);
        table.resize(k+1);
        for(int i = 0; i <= k; i++) {
            table[i].resize(n);
        }
        tmp = 1;
        log_table[0] = -1;
        for(int i = 1; i <= n; i++) {
            log_table[i] = log_table[i-1];
            if(tmp == i) {
                log_table[i]++;
                tmp *= 2;
            }
        }
        for(int i = 0; i <= k; i++) {
            for(int j = 0; j < n; j++) {
                if(i == 0) {
                    table[i][j] = j;
                }
                else {
                    table[i][j] = table[i-1][j];
                    if(j+(1 << (i-1)) < n && a[table[i-1][j]] > a[table[i-1][j+(1 << (i-1))]]) {
                        table[i][j] = table[i-1][j+(1 << (i-1))];
                    }
                }
            }
        }
    }
    // [l,r)
    int query(int l,int r) {
        int len = log_table[r-l];
        return min(A[table[len][l]],A[table[len][r-(1 << len)]]);
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H,W;
    cin >> H >> W;
    vector<string>S(H);
    for(int i = 0; i < H; i++) {
        cin >> S[i];
    }
    vector<int>A(W,0);
    SparseTable now(W,A);
    for(int i = H-2; i >= 0; i--) {
        vector<int>nxt(W,inf);
        int mi = -1;
        for(int j = 0; j < W; j++) {
            if(S[i][j] == '#') {
                mi = j;
                continue;
            }
            int l = -1,r = W;
            while(l+1 < r) {
                int mid = (l+r)/2;
                if(now.query(max(mi+1,j-mid),j+1) <= mid) {
                    r = mid;
                }
                else {
                    l = mid;
                }    
            }
            if(r != W) {
                nxt[j] = r;
            }
        }
        mi = W;
        for(int j = W-1; j >= 0; j--) {
            if(S[i][j] == '#') {
                mi = j;
                continue;
            }
            int l = -1,r = W;
            while(l+1 < r) {
                int mid = (l+r)/2;
                if(now.query(j,min(mi-1,j+mid)+1) <= mid) {
                    r = mid;
                }
                else {
                    l = mid;
                }    
            }
            if(r != W) {
                nxt[j] = min(nxt[j],r);
            }
        }
        SparseTable nsp(W,nxt);
        now = nsp;
    }
    for(int i = 0; i < W; i++) {
        cout << now.query(i,i+1) << "\n";
    }
}
0