QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#532793 | #5080. Folding Stick | BongoCatEnjoyer# | WA | 0ms | 3808kb | C++14 | 2.1kb | 2024-08-25 11:57:39 | 2024-08-25 11:57:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define forn(i, n) for (ll i = 0; i < n; ++i)
#define forr(i, s, n) for (ll i = s; i < n; ++i)
#define fori(i, s, n) for (ll i = s; i > n; --i)
#define fora(i, n) for (auto i: n)
#define vi vector<int>
#define vll vector<ll>
#define prints(n) cout << (n) << " "
#define println(n) cout << (n) << "\n"
#define newl() cout << "\n"
const int MOD = 998244353;
// const int MOD = 1e9 + 7;
void solve() {
ll n; cin >> n;
vector<ll> a(n); fora(&x, a) cin >> x;
vector<ll> suf(n + 1), pre(n + 1);
fori(i, n - 1, -1) suf[i] = suf[i + 1] + a[i];
forn(i, n) pre[i + 1] = pre[i] + a[i];
// fora(x, suf) prints(x); newl();
// fora(x, pre) prints(x); newl();
vector<pair<ll, ll>> v = {{0, a[0]}};
ll ans = max(a[0], suf[1]);
ll mn = a[0];
forr(i, 1, n) {
mn += a[i];
v.push_back({i, v.back().second + a[i]});
fora(x, v) {
if (pre[i + 1] - pre[x.first + 1] >= x.second) {
v.push_back({i, pre[i + 1] - pre[x.first + 1]});
mn = min(mn, pre[i + 1] - pre[x.first + 1]);
ans = min(ans, max(v.back().second, suf[i + 1]));
}
}
// println(i);
// fora(x, v) {
// prints(x.first); println(x.second);
// }
// println(mn);
fori(j, v.size() - 1, -1) {
// prints(j); println(pre[i + 1] - pre[v[j].first + 1] + v[j].second);
// prints(pre[i + 1]); prints(pre[v[j].first + 1]); println(v[j].second);
if (pre[i + 1] - pre[v[j].first + 1] + v[j].second > mn) {
// println("ERASED");
v.erase(begin(v) + j);
}
}
// println(i);
// fora(x, v) {
// prints(x.first); println(x.second);
// }
}
println(ans);
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
// cin >> t;
while (t--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3524kb
input:
4 3 2 2 3
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
5 1 1 1 1 1
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
7 1 3 2 3 4 2 2
output:
6
result:
ok single line: '6'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
9 5 6 3 4 8 8 2 2 5
output:
9
result:
ok single line: '9'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
10 5 6 3 4 8 6 2 1 8 5
output:
9
result:
ok single line: '9'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
10 5 8 1 2 6 8 4 3 6 5
output:
14
result:
ok single line: '14'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
3 4 2 1
output:
4
result:
ok single line: '4'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
14 7 2 2 2 2 3 4 1 3 5 4 3 1 6
output:
8
result:
ok single line: '8'
Test #9:
score: -100
Wrong Answer
time: 0ms
memory: 3580kb
input:
35 46 93 64 27 72 55 77 11 17 17 79 83 74 26 32 101 54 112 92 111 77 60 51 19 105 11 68 7 100 49 88 54 106 80 57
output:
377
result:
wrong answer 1st lines differ - expected: '366', found: '377'