結果

問題 No.973 余興
ユーザー totori_nyaa
提出日時 2020-01-18 04:47:07
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
MLE  
実行時間 -
コード長 1,064 bytes
コンパイル時間 1,807 ms
コンパイル使用メモリ 175,376 KB
実行使用メモリ 814,720 KB
最終ジャッジ日時 2024-06-26 09:01:57
合計ジャッジ時間 7,961 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 2
other MLE * 1 -- * 53
権限があれば一括ダウンロードができます

ソースコード

diff #

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

set<int> st[5000];
bool dp[5000][5000];

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    
    int n,x;
    cin>>n>>x;
    ll a[n];
    ll sum[n+1]={};
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum[i+1] += a[i] + sum[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i==j) continue;
            st[i].insert(j);
        }
    }
    for(int i=n-1;i>=0;i--){
        for(int j=i+1;j<n;j++){
            int ret = *st[i].upper_bound(i);
            ll dif = sum[ret] - sum[i];
            bool pos = false;
            if(dif <= x) pos = 1;
            auto itr = st[j].lower_bound(j);
            itr--;
            dif = sum[j+1] - sum[*itr];
            if(dif <= x) pos = 1;
            if(pos){
                dp[i][j] = 1;
                st[i].erase(j);
                st[j].erase(i);
            }
        }
    }
    if(dp[0][n-1]){
        cout << "A\n";
    }
    else cout << "B\n";
}
0