QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#532832 | #5080. Folding Stick | BongoCatEnjoyer# | WA | 1ms | 3656kb | C++14 | 1.7kb | 2024-08-25 13:07:06 | 2024-08-25 13:07:07 |
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>
const int MOD = 998244353;
// const int MOD = 1e9 + 7;
void solve() {
int n;
cin >> n;
vi vec(n);
forn(i, n) cin >> vec[i];
int ANS = LLONG_MAX;
int sum = 0;
for (int P = 0; P < min(n, 100LL); P++) {
int l = 1, r = 1e12;
int ans = -1;
while (l <= r) {
int mid = (l + r) / 2;
int cur = mid;
int p = 0;
bool fi = 1;
bool fin = 0;
for (int i = vec.size()-1; i >= 0; i--) {
if (p + vec[i] <= cur) {
p += vec[i];
} else {
cur = p;
if (cur < vec[i]) {
fin = 0;
break;
}
p = vec[i];
}
if (!i) fin = 1;
}
// cout << mid << ' ' << fin << '\n';
if (fin) {
ans = mid;
r = mid - 1;
}
else {
l = mid + 1;
}
}
ANS = min(ANS, max(ans, sum));
if (ans < sum) break;
sum += vec.back();
vec.pop_back();
}
cout << ANS << '\n';
}
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: 3584kb
input:
4 3 2 2 3
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3656kb
input:
5 1 1 1 1 1
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
7 1 3 2 3 4 2 2
output:
6
result:
ok single line: '6'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3500kb
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: 3612kb
input:
10 5 6 3 4 8 6 2 1 8 5
output:
13
result:
wrong answer 1st lines differ - expected: '9', found: '13'