結果

問題 No.973 余興
ユーザー Enjapma_kyoproEnjapma_kyopro
提出日時 2020-01-18 12:31:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,710 ms / 4,000 ms
コード長 4,738 bytes
コンパイル時間 1,596 ms
コンパイル使用メモリ 172,260 KB
実行使用メモリ 359,624 KB
最終ジャッジ日時 2024-06-27 06:11:33
合計ジャッジ時間 54,768 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,710 ms
357,964 KB
testcase_01 AC 1,654 ms
356,560 KB
testcase_02 AC 1,625 ms
358,092 KB
testcase_03 AC 1,616 ms
358,864 KB
testcase_04 AC 1,604 ms
357,964 KB
testcase_05 AC 1,607 ms
358,732 KB
testcase_06 AC 1,608 ms
358,992 KB
testcase_07 AC 1,616 ms
357,840 KB
testcase_08 AC 1,616 ms
357,836 KB
testcase_09 AC 1,639 ms
358,096 KB
testcase_10 AC 1,551 ms
346,960 KB
testcase_11 AC 507 ms
150,736 KB
testcase_12 AC 434 ms
149,964 KB
testcase_13 AC 428 ms
149,964 KB
testcase_14 AC 426 ms
148,940 KB
testcase_15 AC 54 ms
32,456 KB
testcase_16 AC 54 ms
27,648 KB
testcase_17 AC 34 ms
20,224 KB
testcase_18 AC 43 ms
23,808 KB
testcase_19 AC 44 ms
23,808 KB
testcase_20 AC 33 ms
19,968 KB
testcase_21 AC 54 ms
27,264 KB
testcase_22 AC 53 ms
27,264 KB
testcase_23 AC 43 ms
23,808 KB
testcase_24 AC 43 ms
23,552 KB
testcase_25 AC 20 ms
14,848 KB
testcase_26 AC 33 ms
19,840 KB
testcase_27 AC 62 ms
30,080 KB
testcase_28 AC 43 ms
23,808 KB
testcase_29 AC 42 ms
23,552 KB
testcase_30 AC 1,494 ms
353,536 KB
testcase_31 AC 1,500 ms
358,988 KB
testcase_32 AC 1,504 ms
358,096 KB
testcase_33 AC 1,515 ms
358,732 KB
testcase_34 AC 1,511 ms
357,832 KB
testcase_35 AC 1,511 ms
356,552 KB
testcase_36 AC 1,468 ms
350,156 KB
testcase_37 AC 1,480 ms
350,284 KB
testcase_38 AC 1,478 ms
357,708 KB
testcase_39 AC 1,509 ms
357,452 KB
testcase_40 AC 3 ms
9,676 KB
testcase_41 AC 3 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 3 ms
5,376 KB
testcase_44 AC 3 ms
5,376 KB
testcase_45 AC 4 ms
5,376 KB
testcase_46 AC 1,485 ms
353,536 KB
testcase_47 AC 1,486 ms
359,120 KB
testcase_48 AC 1,448 ms
359,624 KB
testcase_49 AC 1,297 ms
334,028 KB
testcase_50 AC 1,465 ms
355,920 KB
testcase_51 AC 1,473 ms
357,964 KB
testcase_52 AC 1,444 ms
357,964 KB
testcase_53 AC 1,433 ms
354,124 KB
testcase_54 AC 1,442 ms
357,964 KB
testcase_55 AC 1,416 ms
357,584 KB
権限があれば一括ダウンロードができます

ソースコード

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];
}

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;
            if(tmp1 > kosuu1){
                // 負けへの遷移がある
                canwin = true;
            }
            if(canwin){
                dp[i][j] = 1;
                sum_r[i][j] = sum_r[i][j-1] + dp[i][j];
                sum_l[i][j] = sum_l[i+1][j] + dp[i][j];
                continue;
            }

            // 右から食べる場合
            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;
            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];
        }
    }
    if(dp[0][n-1] == 2){
        p("B");
    }else{
        p("A");
    }
    return 0;
}
 
 









0