CODE THANKS FESTIVAL 2018(Parallel)

Submission #11204918

Source codeソースコード

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n;
ll a[1010],S[1010];
int dp[2][1010];

void solve(){
    cin >> n;
    ll l=-INF,r=INF;
    rep(i,n){
        cin >> a[i];
        S[i+1]=S[i]+a[i];
    }
    while(r-l>1){
        ll mid=(r+l)/2;
        //cout << l << " " << r << endl;
        rep(i,n){
            dp[0][i]=mod;
            dp[1][i]=-mod;
        }
        dp[0][n]=0;
        dp[1][n]=0;
        per(i,n){
            Rep(j,i+1,n+1){
                int f;
                if(S[j]-S[i]>=mid) f=1;
                else f=-1;
                dp[0][i]=min(dp[0][i],dp[1][j]-f);
                dp[1][i]=max(dp[1][i],dp[0][j]-f);
            }
        }

        // rep(k,2){
        //     rep(i,n+1){
        //         cout << k << " " << i << " " << dp[k][i] << endl;
        //     }
        // }
        if(dp[0][0]<=0) l=mid;
        else r=mid;
    }
    cout << l << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Submission

Task問題 H - Median Game
User nameユーザ名 Chanyuh
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 500
Source lengthソースコード長 1981 Byte
File nameファイル名
Exec time実行時間 82 ms
Memory usageメモリ使用量 256 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - s1.txt,s2.txt
All 500 / 500 01.txt,02.txt,03.txt,04.txt,05.txt,06.txt,07.txt,08.txt,09.txt,10.txt,11.txt,12.txt,13.txt,14.txt,15.txt,16.txt,17.txt,18.txt,19.txt,20.txt,21.txt,22.txt,23.txt,24.txt,25.txt,26.txt,27.txt,28.txt,29.txt,30.txt,s1.txt,s2.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
01.txt AC 1 ms 256 KB
02.txt AC 1 ms 256 KB
03.txt AC 1 ms 256 KB
04.txt AC 1 ms 256 KB
05.txt AC 1 ms 256 KB
06.txt AC 1 ms 256 KB
07.txt AC 1 ms 256 KB
08.txt AC 1 ms 256 KB
09.txt AC 1 ms 256 KB
10.txt AC 1 ms 256 KB
11.txt AC 82 ms 256 KB
12.txt AC 77 ms 256 KB
13.txt AC 69 ms 256 KB
14.txt AC 78 ms 256 KB
15.txt AC 72 ms 256 KB
16.txt AC 79 ms 256 KB
17.txt AC 81 ms 256 KB
18.txt AC 75 ms 256 KB
19.txt AC 79 ms 256 KB
20.txt AC 79 ms 256 KB
21.txt AC 75 ms 256 KB
22.txt AC 78 ms 256 KB
23.txt AC 77 ms 256 KB
24.txt AC 76 ms 256 KB
25.txt AC 80 ms 256 KB
26.txt AC 76 ms 256 KB
27.txt AC 76 ms 256 KB
28.txt AC 82 ms 256 KB
29.txt AC 77 ms 256 KB
30.txt AC 80 ms 256 KB
s1.txt AC 1 ms 256 KB
s2.txt AC 1 ms 256 KB