結果

問題 No.973 余興
ユーザー Enjapma_kyoproEnjapma_kyopro
提出日時 2020-01-18 12:27:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 5,454 bytes
コンパイル時間 1,751 ms
コンパイル使用メモリ 171,564 KB
実行使用メモリ 560,376 KB
最終ジャッジ日時 2023-09-09 13:02:48
合計ジャッジ時間 61,882 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 MLE -
testcase_02 MLE -
testcase_03 MLE -
testcase_04 MLE -
testcase_05 MLE -
testcase_06 MLE -
testcase_07 MLE -
testcase_08 MLE -
testcase_09 MLE -
testcase_10 MLE -
testcase_11 AC 564 ms
288,200 KB
testcase_12 AC 565 ms
287,896 KB
testcase_13 AC 561 ms
287,508 KB
testcase_14 AC 555 ms
287,880 KB
testcase_15 AC 68 ms
130,408 KB
testcase_16 AC 69 ms
132,492 KB
testcase_17 AC 46 ms
105,756 KB
testcase_18 AC 58 ms
120,148 KB
testcase_19 AC 57 ms
120,212 KB
testcase_20 AC 45 ms
103,884 KB
testcase_21 AC 68 ms
132,428 KB
testcase_22 AC 68 ms
132,368 KB
testcase_23 AC 58 ms
120,212 KB
testcase_24 AC 56 ms
118,096 KB
testcase_25 AC 31 ms
83,280 KB
testcase_26 AC 45 ms
103,884 KB
testcase_27 AC 78 ms
140,624 KB
testcase_28 AC 57 ms
120,152 KB
testcase_29 AC 56 ms
116,008 KB
testcase_30 MLE -
testcase_31 MLE -
testcase_32 MLE -
testcase_33 MLE -
testcase_34 MLE -
testcase_35 MLE -
testcase_36 MLE -
testcase_37 MLE -
testcase_38 MLE -
testcase_39 MLE -
testcase_40 AC 3 ms
13,588 KB
testcase_41 AC 3 ms
13,660 KB
testcase_42 AC 3 ms
13,596 KB
testcase_43 AC 4 ms
15,692 KB
testcase_44 AC 3 ms
13,648 KB
testcase_45 AC 7 ms
26,004 KB
testcase_46 MLE -
testcase_47 MLE -
testcase_48 MLE -
testcase_49 MLE -
testcase_50 MLE -
testcase_51 MLE -
testcase_52 MLE -
testcase_53 MLE -
testcase_54 MLE -
testcase_55 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <unistd.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
 
long long int INF = 3e18;
const ll fact_table = 800008;
double Pi = 3.1415926535897932384626;
 
//vector<ll> G[550010];
//vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
// priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
 
 
//ll mod = 998244353;
ll mod = 1000000007;
 
ll rui(ll number1,ll number2){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 
/*
ll fact[fact_table + 5],rfact[fact_table + 5];
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = rui(fact[fact_table],mod - 2);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/
 
ll n,m,num,sum,a,b,c,d,e,g,h,w, i,j,q,r,l;
ll k;
ll ans;
ll x[500005], y[200005], z[200005];
// char s[500005], t[500005];
bool used[3005][3004];
ll dp[5004][5004];
ll sum_l[5005][5005];
ll sum_r[5005][5005];
char s[2005][2005];

ll ruiseki(ll l, ll r){
    return y[r] - y[l];
}
ll solve(ll i, ll j){
    // pe(i);p(j);
    // dp[i][j]の結果を求める
    if(dp[i][j] != 0)return dp[i][j];
    if(i == j){
        dp[i][j] = 2;
        return 2;
    }
    ll l, r;
    l = i;
    r = j;
    vector<ll> v;
    for(ll i=l+1;i<=r;i++){
        // 左を食べる
        if(ruiseki(l, i) <= k)v.pb(solve(i, r));
    }
    for(ll i=l;i<r;i++){
        // 右を食べる
        if(ruiseki(i+1, r+1) <= k)v.pb(solve(l, i));
    }
    bool canwin = false;
    for(ll i=0;i<v.size();i++){
        if(v[i] == 2)canwin = true;
    }
    if(canwin){
        dp[i][j] = 1;
        return 1;
    }else{
        dp[i][j] = 2;
        return 2;
    }
}

int main(){
    /*
    cin.tie(0);
    ios::sync_with_stdio(false);
    */
    cin >> n >> k;
    for(ll i=0;i<n;i++){
        cin >> x[i];
    }
    for(ll i=0;i<n;i++){
        y[i+1] = x[i];
    }
    for(ll i=0;i<n;i++){
        y[i+2] += y[i+1];
    }
    for(ll l=0;l<n;l++){
        for(ll i=0;i+l<n;i++){
            ll j = i + l;
            bool canwin = false;
            // dp[i][j]はどうなるか?
            if(i == j){
                dp[i][j] = 2;
                sum_l[i][j] = 2;
                sum_r[i][j] = 2;
                continue;
            }
            // 左から食べる場合
            ll ok = i, ng = j + 2;
            while(ng - ok > 1){
                ll mid = (ok + ng) / 2;
                if(ruiseki(i, mid) <= k){
                    ok = mid;
                }else{
                    ng = mid;
                }
            }
            if(ok >= j){
                canwin = true;
            }
            // ruiseki(i, ok) <= k
            ll tmp1 = sum_l[i+1][j] - sum_l[ok+1][j];
            ll kosuu1 = ok - i;
            assert(tmp1 >= kosuu1);
            if(tmp1 > kosuu1){
                // 負けへの遷移がある
                canwin = true;
            }

            // 右から食べる場合
            ok = j+1, ng = i - 1;
            while(ok - ng > 1){
                ll mid = (ok + ng) / 2;
                if(ruiseki(mid, j+1) <= k){
                    ok = mid;
                }else{
                    ng = mid;
                }
            }
            if(ok <= i + 1){
                canwin = true;
            }
            ll tmp2 = sum_r[i][j-1] - sum_r[i][ok-2];
            
            ll kosuu2 = j - ok + 1;
            assert(tmp2 >= kosuu2);
            assert(kosuu2 * 2 >= tmp2);
            if(tmp2 > kosuu2){
                // 負けへの遷移がある
                canwin = true;
            }
            if(canwin){
                dp[i][j] = 1;
            }else{
                dp[i][j] = 2;
            }
            sum_r[i][j] = sum_r[i][j-1] + dp[i][j];
            sum_l[i][j] = sum_l[i+1][j] + dp[i][j];
        }
    }
    for(ll i=0;i<n;i++){
        for(ll j=0;j<n;j++){
            //pe(dp[i][j]);
            // pe(sum_r[i][j]);
        }
        //el;
    }
    if(dp[0][n-1] == 2){
        p("B");
    }else{
        p("A");
    }
    return 0;
}
 
 









0