QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#533398 | #5080. Folding Stick | skrghariapa# | WA | 0ms | 3664kb | C++17 | 1.1kb | 2024-08-25 21:56:27 | 2024-08-25 21:56:28 |
Judging History
answer
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
using ll = long long;
vector<int> memo;
vector<int> vec;
vector<int> psum;
int dp(int target){
if(memo[target] != -1) return memo[target];
if(target == 0) return vec[0];
int l = 0, r = target -1;
int res = psum[target];
while(l<=r){
int mid = (l+r)/2;
if(dp(mid) < psum[target] - psum[mid]){
res = psum[target] - psum[mid];
l+=1;
}
else{
r -= 1;
}
}
return memo[target] = res;
}
int main(){
int 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(int i = 1 ; i < n; i++){
cin>>vec[i];
psum[i] = psum[i-1] + vec[i];
}
dp(n-2);
int ans = INT_MAX;
for(int i = 0; i < n-1; 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: 3664kb
input:
4 3 2 2 3
output:
4
result:
ok single line: '4'
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3592kb
input:
5 1 1 1 1 1
output:
2
result:
wrong answer 1st lines differ - expected: '1', found: '2'