QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#356462 | #7199. Bomb | vme50 | WA | 1ms | 3892kb | C++17 | 891b | 2024-03-17 20:26:19 | 2024-03-17 20:26:20 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=3e3+5;
int n,a[N];ll b[N],s[N],dp[N][N];
void W(ll &x,ll y) {x=min(x,y);}
ll sqr(int x) {return 1ll*x*x;}
int main()
{
while(~scanf("%d",&n))
{
for(int i=1;i<=n;++i) scanf("%d",&a[i]);
b[0]=b[n]=1e18;for(int i=1;i<n;++i) b[i]=sqr(a[i]-a[i+1]);
for(int i=1;i<=n;++i) s[i]=s[i-1]+min(b[i],b[i-1]);
for(int i=1;i<=n;++i) fill(dp[i]+1,dp[i]+n+1,1e18);dp[1][1]=0;
for(int i=1;i<=n;++i)
{
for(int j=i;j<=n;++j)
{
if(i<j) W(dp[i+1][j],dp[i][j]+b[i]);
if(j<n) W(dp[i][j+1],dp[i][j]+b[j]);
}
for(int j=n,t=n;j>i;--j)
{
if(j<n) W(dp[i][j],dp[i][j+1]);while(t && a[t]>a[j]*2-a[i]) --t;
W(dp[j][t],dp[i][j]+sqr(a[i]-a[j])+s[j-1]-s[i]);
if(t<n) W(dp[j][t+1],dp[i][j]+sqr(a[j]-a[t+1])+s[j-1]-s[i]);
}
}printf("%lld\n",dp[n][n]);
}return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3836kb
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: 3892kb
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 60 1999996000002 1951077172386 1999988000020
result:
wrong answer 2nd words differ - expected: '59', found: '60'