QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#533434 | #5080. Folding Stick | skrghariapa# | WA | 0ms | 3700kb | C++14 | 864b | 2024-08-25 23:03:11 | 2024-08-25 23:03:12 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long int
using namespace std;
vector <int> memo;
vector <int> pref;
int dp(int target) {
if (memo[target] != -1) return memo[target];
if (memo[target] == 1) return pref[target];
int l = 1, r = target - 1;
int res = pref[target];
while (l <= r) {
int mid = (l + r) / 2;
if (dp(mid) <= pref[target] - pref[mid]) {
res = pref[target] - pref[mid];
l = mid + 1;
} else {
r = mid - 1;
}
}
return memo[target] = res;
}
int32_t main() {
int n;
cin >> n;
pref.resize(n + 1, 0);
memo.resize(n + 1, -1);
for (int i = 1; i <= n; i++) {
cin >> pref[i];
pref[i] += pref[i - 1];
}
int ans = INT_MAX;
for (int i = 0; i <= n; i++) {
ans = min(ans, max(dp(i), pref[n] - pref[i]));
}
cout << ans << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3688kb
input:
4 3 2 2 3
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3700kb
input:
5 1 1 1 1 1
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
7 1 3 2 3 4 2 2
output:
6
result:
ok single line: '6'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3648kb
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: 3564kb
input:
10 5 6 3 4 8 6 2 1 8 5
output:
13
result:
wrong answer 1st lines differ - expected: '9', found: '13'