QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#244019 | #7199. Bomb | ucup-team004 | WA | 0ms | 3616kb | C++20 | 1.8kb | 2023-11-08 20:27:48 | 2023-11-08 20:27:48 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
constexpr i64 inf = 1E18;
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)), f(n, std::vector<i64>(n));
for (int i = 0; i < n; i++) {
i64 sum = 0;
int max = 0;
for (int j = i + 1; j < n; j++) {
sum += 1LL * (x[j] - x[j - 1]) * (x[j] - x[j - 1]);
max = std::max(max, x[j] - x[j - 1]);
f[i][j] = sum - 1LL * max * max;
}
}
for (int i = 0; i < n; i++) {
int k = i;
i64 min = inf;
std::vector<i64> pre(n, inf);
for (int j = 0; j < i; j++) {
pre[j + 1] = std::min(pre[j], dp[j][i] + 1LL * (x[i] - x[j]) * (x[i] - x[j]));
}
for (int j = i + 1; j < n; j++) {
if (i == 0) {
dp[i][j] = f[i][j] + 1LL * (x[j] - x[i]) * (x[j] - x[i]);
} else {
while (k > 0 && x[i] - x[k - 1] <= x[j] - x[i]) {
k--;
min = std::min(min, dp[k][i]);
}
dp[i][j] = std::min(min + 1LL * (x[j] - x[i]) * (x[j] - x[i]), pre[k]) + f[i][j];
}
}
}
for (int i = 0; i < n - 1; i++) {
ans = std::min(ans, dp[i][n - 1] + 1LL * (x[n - 1] - x[i]) * (x[n - 1] - x[i]));
}
std::cout << ans << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
input:
5 1 4 5 6 10 3 1 2 6
output:
51 33
result:
ok 2 tokens
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3588kb
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 65 1999996000002 1951077172386 1999988000020
result:
wrong answer 2nd words differ - expected: '59', found: '65'