QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#757744 | #4931. Comic Binge | MeatInTheMiddle | WA | 27ms | 126660kb | C++17 | 2.6kb | 2024-11-17 13:04:55 | 2024-11-17 13:04:58 |
Judging History
answer
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll mod = 1e9 + 7;
int a[1001], b[1001];
int psuma[1001];
pii dp[1001][2][10501];
int range_sum(int l, int r) { return l <= r ? psuma[r] - psuma[l - 1] : 0; }
pii ns(int bro, pii cur, int d) {
if (cur.second + d <= a[cur.first]) return {cur.first, cur.second + d};
d -= (a[cur.first] - cur.second), cur = {cur.first, a[cur.first]};
if (cur.first + 1 == bro) return cur;
int lo = cur.first, hi = bro;
while (lo + 1 < hi) {
int mid = (lo + hi) >> 1;
if (range_sum(cur.first + 1, mid) >= d) hi = mid;
else lo = mid;
}
cur = {lo, a[lo]}, d -= range_sum(cur.first + 1, lo);
if (d && lo + 1 < bro) return {lo + 1, min(d, a[lo + 1])};
else return cur;
}
void solve() {
int n;
cin >> n;
for (int i = 0; i <= n; i++)
for (int j = 0; j <= 10000; j++) dp[i][0][j] = dp[i][1][j] = {-1, -1};
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
for (int i = 1; i <= n; i++) psuma[i] = psuma[i - 1] + a[i];
dp[0][0][0] = {0, 0};
for (int i = 0; i < n; i++) {
for (int t = 0; t <= 10000; t++) {
if (dp[i][0][t] != pii(-1, -1)) {
dp[i + 1][1][t + b[i + 1]] = max(dp[i + 1][1][t + b[i + 1]], ns(i + 1, dp[i][0][t], b[i + 1]));
// cout << i + 1 << " " << dp[i][0][t].first << " " << dp[i][0][t].second << " " << b[i + 1] << " : " << ns(i + 1, dp[i][0][t], b[i + 1]).first << " "
// << ns(i + 1, dp[i][0][t], b[i + 1]).second << "\n";
}
if (dp[i][1][t] != pii(-1, -1)) {
dp[i + 1][0][t] = max(dp[i + 1][0][t], dp[i][1][t]);
dp[i + 1][1][t + b[i + 1]] = max(dp[i + 1][1][t + b[i + 1]], ns(i + 1, dp[i][1][t], b[i + 1]));
}
}
}
int ans = 1e9;
for (int i = 0; i <= 10000; i++) {
if (dp[n][0][i] != pii(-1, -1)) {
ans = min(ans, i + a[dp[n][0][i].first] - dp[n][0][i].second + range_sum(dp[n][0][i].first + 1, n));
}
if (dp[n][1][i] != pii(-1, -1)) {
ans = min(ans, i + a[dp[n][1][i].first] - dp[n][1][i].second + range_sum(dp[n][1][i].first + 1, n));
}
}
cout << ans << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int T = 1;
// cin >> T;
while (T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4872kb
input:
6 3 1 1 1 1 2 1 5 3 3 7 4
output:
13
result:
ok single line: '13'
Test #2:
score: 0
Accepted
time: 1ms
memory: 4168kb
input:
2 2 1 1 1
output:
4
result:
ok single line: '4'
Test #3:
score: 0
Accepted
time: 1ms
memory: 4008kb
input:
1 1 1
output:
2
result:
ok single line: '2'
Test #4:
score: 0
Accepted
time: 4ms
memory: 30404kb
input:
161 146 662 336 441 626 77 362 697 911 248 879 40 435 60 518 62 475 908 185 740 435 899 188 673 716 529 524 305 321 998 4 363 598 471 650 379 6 980 971 175 664 328 294 681 201 64 926 608 310 478 404 284 634 239 891 515 433 368 929 457 593 338 432 971 593 134 355 97 658 344 653 592 822 660 403 398 38...
output:
80587
result:
ok single line: '80587'
Test #5:
score: -100
Wrong Answer
time: 27ms
memory: 126660kb
input:
747 4 609 179 580 613 171 82 687 882 977 720 609 967 329 508 803 301 837 550 416 931 416 521 937 268 723 878 33 372 426 2 94 248 979 319 576 859 644 459 365 445 668 337 572 881 775 946 901 992 405 377 896 967 66 792 686 676 232 245 539 217 774 167 747 923 722 295 483 454 195 494 206 779 536 845 438 ...
output:
375236
result:
wrong answer 1st lines differ - expected: '375240', found: '375236'