QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#244477 | #7199. Bomb | ucup-team004 | WA | 0ms | 3612kb | C++20 | 2.3kb | 2023-11-09 09:49:52 | 2023-11-09 09:49:53 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
constexpr i64 inf = 1E18;
i64 square(i64 n) {
return n * n;
}
void chmin(i64 &a, i64 b) {
if (b < a) {
a = b;
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
while (std::cin >> n) {
std::vector<int> x(n);
for (int i = 0; i < n; i++) {
std::cin >> x[i];
}
if (n == 1) {
std::cout << 0 << "\n";
continue;
}
i64 ans = inf;
std::vector dp(n, std::vector<i64>(n, inf)), f(n, std::vector<i64>(n));
for (int i = 0; i < n; i++) {
i64 sum = 0;
for (int j = i + 1; j < n; j++) {
sum += square(x[j] - x[j - 1]);
f[i][j] = sum;
}
}
for (int i = 0; i < n - 1; i++) {
int k = i;
i64 min = inf, min1 = inf, min2 = inf;
std::vector<i64> pre(n, inf);
for (int j = 0; j < i; j++) {
pre[j + 1] = std::min(pre[j], dp[i][k]);
chmin(min1, dp[j][i]);
chmin(min2, dp[j][i] - square(std::min(x[i + 1] - x[i], x[i] - x[j])));
}
for (int j = i + 1; j < n; j++) {
if (i == 0) {
dp[i][j] = dp[j][i] = f[i][j] + square(x[j] - x[i]);
} else {
while (k > 0 && x[i] - x[k - 1] <= x[j] - x[i]) {
k--;
chmin(min, dp[i][k] - square(x[i] - x[k]));
}
chmin(dp[i][j], std::min(min + square(x[j] - x[i]), pre[k]) + f[i][j]);
chmin(dp[i][j], pre[i] + std::max(0LL, square(x[j] - x[i]) - square(x[i] - x[i - 1])) + f[i][j]);
chmin(dp[j][i], min1 + f[i][j] + square(x[j] - x[i]) - square(std::min(x[i] - x[i - 1], x[i + 1] - x[i])));
chmin(dp[j][i], min2 + f[i][j] + square(x[j] - x[i]));
}
}
}
for (int i = 0; i < n - 1; i++) {
chmin(ans, dp[i][n - 1]);
chmin(ans, dp[n - 1][i]);
}
std::cout << ans << "\n";
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
input:
5 1 4 5 6 10 3 1 2 6
output:
51 33
result:
ok 2 tokens
Test #2:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
18 1 2 3 6 11 23 47 106 235 551 1301 3159 7741 19320 48629 123867 317955 823065 5 1 5 6 7 11 2 1 1000000 3 1 12345 1000000 4 1 2 3 1000000
output:
554621353432 59 1999996000002 1951077172386 1999988000020
result:
ok 5 tokens
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3528kb
input:
5 1 2 5 6 7 5 1 4 5 7 10 5 1 2 5 7 10 5 1 4 5 7 10 5 1 2 5 6 7 5 1 4 5 7 10 5 1 2 5 6 7 5 1 2 5 6 7 5 2 5 6 7 9 5 2 5 6 7 9 5 1 4 5 7 10 5 2 3 5 6 9 5 2 5 6 7 9 5 1 2 5 6 7 5 2 3 6 8 9 5 1 2 5 7 10 5 2 3 5 6 9 5 1 4 5 7 10 5 1 2 5 6 7 5 1 2 5 7 10 5 2 5 6 7 9 5 1 2 5 7 10 5 1 4 5 7 10 5 2 3 6 8 9 5 ...
output:
21 32 37 32 21 32 21 21 27 27 32 24 27 21 24 37 24 32 21 37 27 37 32 24 27 27 27 27 24 24 32 27 24 24 27 21 21 32 32 21 24 27 24 27 21 27 37 37 37 27 32 21 24 32 32 24 24 21 27 24 37 27 21 32 37 24 27 21 27 37 21 37 32 24 32 24 32 37 21 32 21 27 21 24 24 27 27 24 32 24 24 27 37 24 27 32 24 21 24 24
result:
wrong answer 2nd words differ - expected: '37', found: '32'