QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#218232 | #6219. 病毒感染 | luyiming123 | 100 ✓ | 19ms | 51336kb | C++14 | 735b | 2023-10-17 21:06:44 | 2023-10-17 21:06:44 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const int N = 3005;
int n; i64 a[N], w[N][N], dp[N];
int main(void)
{
scanf("%d", &n);
for(int i = 1; i <= n; i++) scanf("%lld", &a[i]), a[i] += a[i - 1];
for(int i = 1; i <= n; i++)
{
w[i][i] = 0;
}
for(int len = 2; len <= n; len++)
{
for(int l = 1, r; l + len - 1 <= n; l++)
{
r = l + len - 1;
w[l][r] = w[l + 1][r] + min(2ll * (a[r] - a[l]), 3ll * (r - l) * (a[l] - a[l - 1]) + a[r] - a[l]);
}
}
for(int i = 1; i <= n; i++)
{
dp[i] = 1e18;
for(int j = 0; j < i; j++)
{
dp[i] = min(dp[i], dp[j] + w[j + 1][i] + (a[n] - a[i]) * (4ll * (i - j) - 2ll));
}
}
printf("%lld\n", dp[n]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 10
Accepted
time: 0ms
memory: 3952kb
input:
10 9 5 6 9 42 9 8 26 10 5
output:
1224
result:
ok single line: '1224'
Test #2:
score: 10
Accepted
time: 1ms
memory: 6016kb
input:
20 1 6 10 5 9 2 22 10 7 9 9 3 10 38 2 2 5 5 9 6
output:
3153
result:
ok single line: '3153'
Test #3:
score: 10
Accepted
time: 0ms
memory: 3992kb
input:
20 198 20 61 14 62 46 95 67 817 25 80 77 30 12 99 28 29 38 68 945
output:
56307
result:
ok single line: '56307'
Test #4:
score: 10
Accepted
time: 1ms
memory: 6004kb
input:
50 31 69 63 4 28 31 72 68 188 111 6 94 11 32 7 53 9 66 7 71 233 97 35 93 33 98 81 50 80 24 95 74 63 96 39 998 98 62 64 24 95 18 90 66 5 669 406 74 40 33
output:
272038
result:
ok single line: '272038'
Test #5:
score: 10
Accepted
time: 1ms
memory: 8088kb
input:
60 47 733 3 22 89 74 98 90 97 40 462 15 10 42 19 59 40 1652 85 33 83 81 1396 60 27 44 10 1642 649 78 87 27 34 11 91 732 58 60 56 84 82 4 21 13 71 50 97 49 53 1963 40 24 1460 37 27 11 63 47 94 69
output:
672631
result:
ok single line: '672631'
Test #6:
score: 10
Accepted
time: 1ms
memory: 8396kb
input:
200 254 483 243 2572 103 14035 273 4433 24333 6919 625 28976 11642 357 27077 243 22982 14933 989 283 308 298 4054 884 81 7167 983 19015 524 900 893 530 19967 651 948 307 870 381 322 769 686 469 333 352 846 26072 29118 11070 19878 428 17604 4029 5575 457 17931 19272 11878 23011 19988 38 143 754 442 5...
output:
161370106
result:
ok single line: '161370106'
Test #7:
score: 10
Accepted
time: 0ms
memory: 16444kb
input:
500 458 194 44523981 606 43934438 6159389 300 43021920 894 44 460 124 482 933 277 242 454 160 10215993 977 873 73 146 52 932 338 887 63 48620898 914 919 505 705 12878909 992 41505223 658 583 441 491 482 566 220 199 177 290 853 496 926 854 586 649 15213125 30963586 683 299 14547022 152 291 40 300 577...
output:
499169221984
result:
ok single line: '499169221984'
Test #8:
score: 10
Accepted
time: 3ms
memory: 35632kb
input:
1500 8434349 8440084 9530 8791 6245 4089126 8651136 7872 7095981 4086 9631 704 1285 9806 900 780056 1075 97 7183151 8796200 3056 94644 5368 8592 5569 9758412 9794 2346 843 2221 7319 4140 9435826 7163 4332458 7372 990077 8909827 1625 3746 8070274 3782908 3660 4448 7115180 6362 3433771 4401 7430921 54...
output:
2924731620225
result:
ok single line: '2924731620225'
Test #9:
score: 10
Accepted
time: 9ms
memory: 40872kb
input:
2000 3250 752 5215 4929 802 1502 6803 4330 7438 3824 7094 9657 8879 7840 4859 1126 4054 5410 8046 3183 2077 8956 5195 2171 3770 7702 4124 3686 4130 2477 5512 790 3437 5903 8501 6091 1632 7756 7345 2980 3954 4299 2695 137 3131 9680 3994 5274 4808 333 2784 8256 6590 7302 5420 7303 6310 8076 2046 6596 ...
output:
532896009264
result:
ok single line: '532896009264'
Test #10:
score: 10
Accepted
time: 19ms
memory: 51336kb
input:
3000 126582858 4261 183 8920 4665 3897 4493 3972 6492 6116 5451 9982 168888158 713729112 6837 83005688 9800 3256 71945990 6781 5209 354562458 6023 6346 167302968 9113 2703 855665745 111 763453269 2287 1896 148235537 147940184 1791 7502 486102179 262017942 313 8833 434228825 551 1465 1111 5349 272958...
output:
1149661414335658
result:
ok single line: '1149661414335658'