結果

問題 No.2657 Falling Block Game
ユーザー umimelumimel
提出日時 2024-03-01 23:10:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 422 ms / 2,000 ms
コード長 3,609 bytes
コンパイル時間 2,378 ms
コンパイル使用メモリ 189,476 KB
実行使用メモリ 15,184 KB
最終ジャッジ日時 2024-03-01 23:10:30
合計ジャッジ時間 8,397 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 45 ms
14,336 KB
testcase_05 AC 422 ms
15,184 KB
testcase_06 AC 178 ms
10,496 KB
testcase_07 AC 356 ms
10,448 KB
testcase_08 AC 183 ms
6,676 KB
testcase_09 AC 159 ms
14,336 KB
testcase_10 AC 140 ms
6,676 KB
testcase_11 AC 141 ms
6,676 KB
testcase_12 AC 137 ms
6,676 KB
testcase_13 AC 147 ms
6,676 KB
testcase_14 AC 145 ms
6,676 KB
testcase_15 AC 139 ms
6,676 KB
testcase_16 AC 137 ms
6,676 KB
testcase_17 AC 137 ms
6,676 KB
testcase_18 AC 138 ms
6,676 KB
testcase_19 AC 144 ms
6,676 KB
testcase_20 AC 57 ms
6,676 KB
testcase_21 AC 57 ms
6,676 KB
testcase_22 AC 58 ms
6,676 KB
testcase_23 AC 58 ms
6,676 KB
testcase_24 AC 63 ms
6,676 KB
testcase_25 AC 58 ms
6,676 KB
testcase_26 AC 58 ms
6,676 KB
testcase_27 AC 57 ms
6,676 KB
testcase_28 AC 57 ms
6,676 KB
testcase_29 AC 56 ms
6,676 KB
testcase_30 AC 129 ms
14,336 KB
testcase_31 AC 127 ms
14,336 KB
testcase_32 AC 127 ms
14,336 KB
testcase_33 AC 129 ms
14,336 KB
testcase_34 AC 127 ms
14,336 KB
testcase_35 AC 129 ms
14,336 KB
testcase_36 AC 127 ms
14,336 KB
testcase_37 AC 127 ms
14,336 KB
testcase_38 AC 128 ms
14,336 KB
testcase_39 AC 125 ms
14,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
const ll MOD1000000007 = 1000000007;
const ll MOD998244353 = 998244353;
const ll MOD[3] = {999727999, 1070777777, 1000000007};
const ll LINF = 1LL << 60LL;
const int IINF = (1 << 30) - 1;


void solve(){
    int h, w; cin >> h >> w;
    vector<vector<char>> s(h, vector<char>(w));
    for(int i=0; i<h; i++)for(int j=0; j<w; j++) cin >> s[i][j];

    vector<vector<int>> ans(h, vector<int>(w, IINF));
    for(int j=0; j<w; j++) ans[h-1][j] = 0;
    for(int i=h-2; i>=0; i--){
        //左から走査
        {
            //st1 : value, st2 : pos, st3 : st1->st2への変換点
            multiset<int> st1;
            set<int> st2;
            set<pair<int, int>> st3;
            for(int j=0; j<w; j++){
                if(s[i][j] == '#'){
                    st1.clear();
                    st2.clear();
                    st3.clear();
                }else{
                    // add under
                    if(ans[i+1][j] != IINF){
                        st1.insert(ans[i+1][j]);
                        st3.insert({ans[i+1][j]+j, j});
                    }

                    // move st1 -> st2
                    if(!st3.empty()){
                        while((*st3.begin()).fi == j){
                            int pos = (*st3.begin()).se;
                            st1.erase(st1.lower_bound(ans[i+1][pos]));
                            st2.insert(-pos);
                            st3.erase(st3.begin());
                            if(st3.empty()) break;
                        }
                    }

                    // calc ans
                    if(!st1.empty()) ans[i][j] = min(ans[i][j], *st1.begin());
                    if(!st2.empty()) ans[i][j] = min(ans[i][j], j + *st2.begin());
                }
            }
        }

        //右から走査
        {
            //st1 : value, st2 : pos, st3 : st1->st2への変換点
            multiset<int> st1;
            set<int> st2;
            set<pair<int, int>> st3;
            for(int j=w-1; j>=0; j--){
                if(s[i][j] == '#'){
                    st1.clear();
                    st2.clear();
                    st3.clear();
                }else{
                    // add under
                    if(ans[i+1][j] != IINF){
                        st1.insert(ans[i+1][j]);
                        st3.insert({-(j-ans[i+1][j]), j});
                    }

                    // move st1 -> st2
                    if(!st3.empty()){
                        while((*st3.begin()).fi == -j){
                            int pos = (*st3.begin()).se;
                            st1.erase(st1.lower_bound(ans[i+1][pos]));
                            st2.insert(pos);
                            st3.erase(st3.begin());
                            if(st3.empty()) break;
                        }
                    }

                    // calc ans
                    if(!st1.empty()) ans[i][j] = min(ans[i][j], *st1.begin());
                    if(!st2.empty()) ans[i][j] = min(ans[i][j], *st2.begin() - j);
                }
            }
        }
    }

    for(int j=0; j<w; j++) cout << ans[0][j] << endl;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int T=1;
    //cin >> T;
    while(T--) solve();
}
0