QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#533419#5080. Folding Stickskrghariapa#WA 0ms3644kbC++201.1kb2024-08-25 22:37:212024-08-25 22:37:22

Judging History

你现在查看的是最新测评结果

  • [2024-08-25 22:37:22]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3644kb
  • [2024-08-25 22:37:21]
  • 提交

answer

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
using ll = long long;

vector<ll> memo;
vector<ll> vec;
vector<ll> psum;

ll dp(ll target){
    if(memo[target] != -1) return memo[target];
    if(target == 0) return vec[0];
    ll l = 0, r = target -1;
    ll res = psum[target];
    while(l<=r){
        ll mid = l + (r - l) / 2;
        if(dp(mid) <= psum[target] - psum[mid]){
            res = psum[target] - psum[mid];
            l = mid +1;
        }
        else{
            r = mid - 1;
        }
    }
    return memo[target] = res;
}


int main(){
    fastio;
    ll n, inp, sum = 0;
    cin>>n;
    psum.resize(n+3);
    vec.resize(n+3, -1);
    memo.resize(n+3, -1);

    cin>>vec[0];
    psum[0] = vec[0];
    for(ll i = 1 ; i < n; i++){
        cin>>vec[i];
        psum[i] = psum[i-1] + vec[i];
        //cout << psum[i] << " ";
    }
    //cout << endl;
    ll ans = INT_MAX;
    for(ll i = 0; i < n; i++){
        // cout<< dp(i)<<endl;
        ans = min(ans,  max(dp(i), psum[n-1] - psum[i]));
    }
    cout<<ans<<endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3604kb

input:

4
3 2 2 3

output:

4

result:

ok single line: '4'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

5
1 1 1 1 1

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

7
1 3 2 3 4 2 2

output:

6

result:

ok single line: '6'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

9
5 6 3 4 8 8 2 2 5

output:

9

result:

ok single line: '9'

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3644kb

input:

10
5 6 3 4 8 6 2 1 8 5

output:

13

result:

wrong answer 1st lines differ - expected: '9', found: '13'