結果

問題 No.2539 スライムゲーム
ユーザー momoyuumomoyuu
提出日時 2023-11-10 23:19:32
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,399 bytes
コンパイル時間 4,634 ms
コンパイル使用メモリ 258,056 KB
実行使用メモリ 7,552 KB
最終ジャッジ日時 2023-11-10 23:19:38
合計ジャッジ時間 4,441 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,548 KB
testcase_01 AC 3 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 3 ms
6,548 KB
testcase_06 AC 3 ms
6,548 KB
testcase_07 AC 2 ms
6,548 KB
testcase_08 AC 2 ms
6,548 KB
testcase_09 AC 3 ms
6,548 KB
testcase_10 AC 3 ms
6,548 KB
testcase_11 AC 3 ms
6,548 KB
testcase_12 AC 3 ms
6,548 KB
testcase_13 AC 3 ms
6,548 KB
testcase_14 AC 3 ms
6,548 KB
testcase_15 AC 3 ms
6,548 KB
testcase_16 AC 3 ms
6,548 KB
testcase_17 AC 3 ms
6,548 KB
testcase_18 AC 3 ms
6,548 KB
testcase_19 AC 2 ms
6,548 KB
testcase_20 AC 3 ms
6,548 KB
testcase_21 AC 2 ms
6,548 KB
testcase_22 WA -
testcase_23 AC 3 ms
6,548 KB
testcase_24 AC 3 ms
6,548 KB
testcase_25 AC 3 ms
6,548 KB
testcase_26 AC 2 ms
6,548 KB
testcase_27 AC 2 ms
6,548 KB
testcase_28 AC 9 ms
6,548 KB
testcase_29 AC 12 ms
6,548 KB
testcase_30 AC 17 ms
7,552 KB
testcase_31 AC 5 ms
6,548 KB
testcase_32 AC 6 ms
6,548 KB
testcase_33 AC 7 ms
6,548 KB
testcase_34 AC 13 ms
6,548 KB
testcase_35 AC 14 ms
6,548 KB
testcase_36 AC 15 ms
6,548 KB
testcase_37 AC 14 ms
6,548 KB
testcase_38 AC 17 ms
7,552 KB
testcase_39 AC 16 ms
7,552 KB
testcase_40 AC 17 ms
7,552 KB
testcase_41 AC 17 ms
7,552 KB
testcase_42 AC 17 ms
7,552 KB
testcase_43 AC 17 ms
7,552 KB
testcase_44 AC 17 ms
7,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    vector<ll> ndp(1<<17,0);
    ndp[0] = 1;
    int no = -1;
    for(int i = 1;i<1<<17;i++){
        for(int j = 0;j<i;j++) ndp[i] += ndp[j];
        ndp[i]++;
        if(ndp[i]>1e18){
            no = i;
            break;
        }
    }
    string s;
    cin>>s;
    ll ans = 0;
    int n = s.size();
    stack<int> st;
    set<int> ss;
    bool ok = false;
    vector<ll> dp(n+1,0);
    for(int i = n-1;i>=0;i--){
        if(s[i]==')'){
            st.push(i);
            continue;
        }
        if(st.empty()){
            ans += 1;
            break;
        }
        int ni = st.top();
        st.pop();
        if(ni==i+1){
            dp[i] = 1;
            ss.insert(i);
            if(st.empty()) ans += dp[i];
            ans = min(ans,(ll)2e18);
            continue;
        }
        ll sum = 0;
        while(ss.size()){
            auto itr = ss.begin();
            int nk = *itr;
            if(nk>ni) break;
            sum += dp[nk];
            sum = min(sum,(ll)2e18);
            ss.erase(nk);
        }
        if(sum>=no){
            dp[i] = 2e18;
        }
        if(sum<=no) dp[i] = ndp[sum];
        ss.insert(i);
        if(st.empty()) ans += dp[i];
        ans = min(ans,(ll)2e18);
    }
    if(!st.empty()) ans++;
    if(ans<=1e18) cout<<ans<<endl;
    else cout<<"INFTY\n";
}

0