QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#346982 | #7199. Bomb | rageOfThunder | WA | 155ms | 144836kb | C++14 | 2.2kb | 2024-03-09 09:27:15 | 2024-03-09 09:27:15 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define mk make_pair
#define fi first
#define se second
using namespace std;
inline int read(){
int x=0,f=1;char c=getchar();
for(;(c<'0'||c>'9');c=getchar()){if(c=='-')f=-1;}
for(;(c>='0'&&c<='9');c=getchar())x=x*10+(c&15);
return x*f;
}
const int mod=998244353;
int ksm(int x,ll y,int p=mod){
int ans=1;y%=(p-1);
for(int i=y;i;i>>=1,x=1ll*x*x%p)if(i&1)ans=1ll*ans*x%p;
return ans%p;
}
int inv(int x,int p=mod){return ksm(x,p-2,p)%p;}
mt19937 rnd(time(0));
int randint(int l,int r){return rnd()%(r-l+1)+l;}
void add(int &x,int v){x+=v;if(x>=mod)x-=mod;}
void Mod(int &x){if(x>=mod)x-=mod;}
int cmod(int x){if(x>=mod)x-=mod;return x;}
template<typename T>void cmax(T &x,T v){x=max(x,v);}
template<typename T>void cmin(T &x,T v){x=min(x,v);}
const int N=3005;
int n,pos[N],tl[N],tr[N];
ll f[2][N][N];
const ll INF=1e15;
void clr(){
for(int i=0;i<=n;i++)pos[i]=tl[i]=tr[i]=0;
for(int c=0;c<=1;c++)for(int i=0;i<=n;i++)for(int j=0;j<=n;j++)f[c][i][j]=INF;
}
void solve(){
if(n==1)return puts("0"),void();
pos[0]=-1e6,pos[n+1]=2e6;
tl[1]=1,tr[1]=2,tl[n]=n-1,tr[n]=n;
for(int i=2;i<=n-1;i++){
int len=max(pos[i]-pos[i-1],pos[i+1]-pos[i]);
tl[i]=lower_bound(pos+1,pos+n+1,pos[i]-len)-pos;
tr[i]=upper_bound(pos+1,pos+n+1,pos[i]+len)-pos-1;
}
auto sq=[&](int x){return 1ll*x*x;};
int cur=0;
f[cur][1][2]=sq(pos[2]-pos[1]);
for(int i=2;i<=n;i++){
memset(f[cur^1],63,sizeof(f[cur^1]));
for(int j=1;j<=i-1;j++)for(int k=i;k<=n;k++)if(f[cur][j][k]<=INF){
// cout<<"f "<<i-1<<" "<<j<<" "<<k<<" = "<<f[cur][j][k]<<endl;
int jj=(j==i-1?i:j);
cmin(f[cur^1][jj][k],f[cur][j][k]+sq(pos[i]-pos[i-1]));
if(i+1<=n){
cmin(f[cur^1][j][max(k,i+1)],f[cur][j][k]+sq(pos[i+1]-pos[i]));
jj=(tl[i]<=j?i:j);
cmin(f[cur^1][jj][max(k,tr[i])],f[cur][j][k]+sq(max(pos[i]-pos[i-1],pos[i+1]-pos[i])));
}
}
cur^=1;
}
cout<<f[cur][n][n]<<endl;
clr();
}
signed main(void){
#ifndef ONLINE_JUDGE
freopen("in.in","r",stdin);
#endif
memset(f,63,sizeof(f));
while(cin>>n){
for(int i=1;i<=n;i++)cin>>pos[i];
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 35ms
memory: 144836kb
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: 155ms
memory: 144836kb
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'