QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#629695 | #8572. Passing Game | Grand_Elf | WA | 67ms | 10484kb | C++17 | 2.2kb | 2024-10-11 14:15:28 | 2024-10-11 14:15:30 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
const int K = 70;
const long long inf = 1e18;
int T, n, k, topl, topr, x[N], v[N], id[N], rk[N], stkl[N], stkr[N];
long long ans, dp[K], ndpl[K], ndpr[K];
bool cmp(int i, int j) {
return x[i] < x[j];
}
void work() {
cin >> n >> k;
k = min(k, 64);
for (int i = 1; i <= n; i++) {
cin >> x[i];
}
for (int i = 1; i <= n; i++) {
cin >> v[i];
}
for (int i = 1; i <= n; i++) {
id[i] = i;
}
sort(id + 1, id + n + 1, cmp);
for (int i = 1; i <= n; i++) {
rk[id[i]] = i;
}
topl = 0;
stkl[++topl] = 1;
for (int i = rk[1] - 1; i >= 1; i--) {
if (v[id[i]] < v[stkl[topl]]) {
stkl[++topl] = id[i];
}
}
topr = 0;
stkr[++topr] = 1;
for (int i = rk[1] + 1; i <= n; i++) {
if (v[id[i]] < v[stkr[topr]]) {
stkr[++topr] = id[i];
}
}
ans = 0x3f3f3f3f3f3f3f3f;
memset(ndpl, 0x3f, sizeof(ndpl));
memset(ndpr, 0x3f, sizeof(ndpr));
ndpl[0] = 0;
ndpr[0] = 0;
for (int l = 1, r = 1; l <= topl || r <= topr; ) {
if (r > topr || l <= topl && v[stkl[l]] >= v[stkr[r]]) {
for (int j = 0; j <= k; j++) {
dp[j] = ndpl[j];
ans = min(ans, dp[j] + 1ll * abs(x[n] - x[stkl[l]]) * v[stkl[l]]);
}
memset(ndpl, 0x3f, sizeof(ndpl));
for (int j = 0; j <= k; j++) {
if (l + 1 <= topl) {
ndpl[j] = min(ndpl[j], dp[j] + 1ll * (x[stkl[l]] - x[stkl[l + 1]]) * v[stkl[l]]);
}
if (r <= topr) {
ndpr[j + 1] = min(ndpr[j + 1], dp[j] + 1ll * (x[stkr[r]] - x[stkl[l]]) * v[stkl[l]]);
}
}
l++;
} else {
for (int j = 0; j <= k; j++) {
dp[j] = ndpr[j];
ans = min(ans, dp[j] + 1ll * abs(x[n] - x[stkr[r]]) * v[stkr[r]]);
}
memset(ndpr, 0x3f, sizeof(ndpr));
for (int j = 0; j <= k; j++) {
if (r + 1 <= topr) {
ndpr[j] = min(ndpr[j], dp[j] + 1ll * (x[stkr[r + 1]] - x[stkr[r]]) * v[stkr[r]]);
}
if (l <= topl) {
ndpl[j + 1] = min(ndpl[j + 1], dp[j] + 1ll * (x[stkr[r]] - x[stkl[l]]) * v[stkr[r]]);
}
}
r++;
}
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> T;
while (T--) {
work();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7696kb
input:
2 4 2 3 2 1 6 3 1 1 3 2 0 1 2 1 2
output:
7 1
result:
ok 2 number(s): "7 1"
Test #2:
score: 0
Accepted
time: 67ms
memory: 10484kb
input:
1 300000 204334 809492393 304618667 173130445 377106790 364888630 949045125 622060683 557772818 216607577 848817467 862855568 507840723 120816645 639713488 741781998 682531787 685261161 601686403 355792373 162819930 710057718 234560726 998604853 678957602 485413982 855985802 109303681 979706626 4822...
output:
31313390701066
result:
ok 1 number(s): "31313390701066"
Test #3:
score: 0
Accepted
time: 64ms
memory: 8148kb
input:
3 100000 65460 217141764 710454586 789075415 24849107 685675008 839804815 638763480 327755609 43827967 390187172 301370841 622696676 598237196 232099091 211987715 416876077 572665966 73382836 520033984 808399404 752832432 341795744 434460344 535426588 136624537 997406768 297342165 558882675 26863877...
output:
70635841128944 47230361360721 59110547802683
result:
ok 3 number(s): "70635841128944 47230361360721 59110547802683"
Test #4:
score: 0
Accepted
time: 65ms
memory: 9352kb
input:
1 300000 101975 207258305 525434317 528778163 645316642 562113679 143398489 9114413 669854123 106324041 841914487 21419012 308025536 689200225 263298218 39377353 860366080 24610184 43404209 529054797 902238799 422737070 484129934 967667618 953541323 338625285 115085955 363490839 998893783 877857789 ...
output:
40311829457542
result:
ok 1 number(s): "40311829457542"
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 9824kb
input:
18 17 0 500000000 499999997 500000010 499999965 500000118 499999609 500001291 499995739 500014064 499953589 500153157 499494579 501667889 494495965 518163316 440061055 697798520 197798520 59938945 18163316 5504035 1667889 505421 153157 46411 14064 4261 1291 391 118 35 10 3 1 17 1 500000000 499999997...
output:
14971815109 14901483521 14650324374 14596599454 14354482419 14327495899 14085378864 14069829018 13827711983 13814295534 13572178499 13559037370 13316920335 13303815695 13061698660 13061698660 13061698660 13061698660
result:
wrong answer 1st numbers differ - expected: '15506866876', found: '14971815109'