QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#658565 | #7005. Rikka with Consistency | FreeTimeLove | WA | 42ms | 5896kb | C++14 | 3.5kb | 2024-10-19 17:03:12 | 2024-10-19 17:03:13 |
Judging History
answer
#include<bits/stdc++.h>
namespace FRTMLV{
#define ll long long
#define LD long double
#define i7 __int128
#define re return
#define con continue
using namespace std;
template<class T>inline bool ckmin(T &a,T b){re b<a?a=b,1:0;}
template<class T>inline bool ckmax(T &a,T b){re a<b?a=b,1:0;}
const int N=1.5e4+5;
inline int rd(){
int d=1,k=0;char c=getchar();
while(!(c>='0' and c<='9' or c=='-'))c=getchar();if(c=='-')d=-1,c=getchar();
while(c>='0' and c<='9')k=(k<<3)+(k<<1)+(c^48),c=getchar();
return d*k;
}
int n,h[N],K[N];
const int INF=0x3f3f3f3f;
int nd[N],tt=1;
int bk[N];
struct edge{int v;LD w;int nxt;}e[N<<2];
void add(int u,int v,LD w){e[++tt]={v,w,nd[u]};nd[u]=tt;
//printf("[(%d,%d)->(%d,%d):%.2Lf]\n",u/(n+n+1),u%(n+n+1),v/(n+n+1),v%(n+n+1),w);
}
LD d[N];
inline int inc(int x,int y){re x*(n+n+1)+y;}
inline int abs(int x){re x<0?-x:x;}
inline LD gt(LD x,LD y){re sqrtl(x*x+y*y);}
struct node{
LD x;int u;
bool operator <(const node &a)const{re x>a.x;}
};
void Dij(){
priority_queue<node>q;
memset(bk,0,sizeof bk);
int st=inc(0,n+n);
d[st]=0,q.push({0,st});
while(q.size()){
int u=q.top().u;q.pop();
if(bk[u])con;bk[u]=1;
for(int i=nd[u];i;i=e[i].nxt){
int v=e[i].v;
if(ckmin(d[v],d[u]+e[i].w))q.push({d[v],v});
}
}
}
signed main(){
int T=rd();
while(T--){
n=rd();
memset(nd,0,sizeof nd),tt=1;
for(int i=0;i<=n;i++){
h[i]=rd();
if(i)K[i]=h[i]-h[i-1];
}
for(int i=0;i<=n+n;i++){
for(int j=0;j<=n+n;j++){
int id=inc(i,j);
d[id]=INF;
int I=(i+1)>>1,J=(j+1)>>1,ni,nj;
LD w;
if(I>0&&J>0&&((i&1)||(j&1)||h[I]==h[J])){
if(!K[I]&&!(i&1))add(id,inc(i-2,j),1);
if(!K[J]&&!(j&1))add(id,inc(i,j-2),1);
if(K[I]*K[J]>0){
LD nw=i&1?h[J]:h[I];
int di=abs(h[I-1]-nw),dj=abs(h[J-1]-nw);
if(di==dj){
ni=i&1?i-1:i-2,nj=j&1?j-1:j-2;
}
else if(di<dj){
ni=i&1?i-1:i-2,nj=j&1?j:j-1;
}
else{
ni=i&1?i:i-1,nj=j&1?j-1:j-2;
}
int mind=min(di,dj);
w=gt((LD)mind/K[I],mind)+gt((LD)mind/K[J],mind);
add(id,inc(ni,nj),w);
}
}
I=(i)>>1,J=(j)>>1;
if(I<n&&J<n&&((i&1)||(j&1)||h[I]==h[J])){
if(!K[I+1]&&!(i&1))add(id,inc(i+2,j),1);
if(!K[J+1]&&!(j&1))add(id,inc(i,j+2),1);
if(K[I+1]*K[J+1]>0){
LD nw=i&1?h[J]:h[I];
int di=abs(h[I+1]-nw),dj=abs(h[J+1]-nw);
if(di==dj){
ni=i&1?i+1:i+2,nj=j&1?j+1:j+2;
}
else if(di<dj){
ni=i&1?i+1:i+2,nj=j&1?j:j+1;
}
else{
ni=i&1?i:i+1,nj=j&1?j+1:j+2;
}
int mind=min(di,dj);
w=gt((LD)mind/K[I+1],mind)+gt((LD)mind/K[J+1],mind);
add(id,inc(ni,nj),w);
}
}
I=(i)>>1,J=(j+1)>>1;
if(I<n&&J>0&&((i&1)||(j&1)||h[I]==h[J])){
if(!K[I+1]&&!(i&1))add(id,inc(i+2,j),1);
if(!K[J]&&!(j&1))add(id,inc(i,j-2),1);
if(K[I+1]*K[J]<0){
LD nw=i&1?h[J]:h[I];
int di=abs(h[I+1]-nw),dj=abs(h[J-1]-nw);
if(di==dj){
ni=i&1?i+1:i+2,nj=j&1?j-1:j-2;
}
else if(di<dj){
ni=i&1?i+1:i+2,nj=j&1?j:j-1;
}
else{
ni=i&1?i:i+1,nj=j&1?j-1:j-2;
}
int mind=min(di,dj);
w=gt((LD)mind/K[I+1],mind)+gt((LD)mind/K[J],mind);
add(id,inc(ni,nj),w);
}
}
}
}
Dij();
printf("%.15Lf\n",d[inc(n+n,0)]);
}
re 0;
}
/*
1
3
0 1 2 0
2
1
0 0
2
0 1 0
2
4
0 1 1 2 0
4
0 2 1 3 0
*/
}signed main(){re FRTMLV::main();}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5896kb
input:
2 4 0 1 1 2 0 4 0 2 1 3 0
output:
12.128990204491960 22.313624568639947
result:
ok 2 cases
Test #2:
score: -100
Wrong Answer
time: 42ms
memory: 4800kb
input:
500 34 0 12 2 25 18 11 17 7 24 20 19 18 34 26 14 15 11 16 3 19 6 21 34 33 12 6 29 10 27 22 5 7 7 25 0 40 0 18 15 11 15 10 9 26 34 13 35 12 27 36 33 3 7 28 6 24 12 30 38 39 14 14 12 13 24 35 28 35 11 22 19 39 8 6 18 3 0 43 0 25 1 23 21 5 16 36 22 3 31 34 9 3 41 17 11 39 22 0 16 39 15 10 8 33 24 21 20...
output:
1061109567.000000000000000 1061109567.000000000000000 2787.580473720950257 541.334373575637191 1061109567.000000000000000 1951.673466582071729 1213.924537986642280 2017.586964700495137 312.764409849808348 1061109567.000000000000000 138.614373840089229 2149.988607593458737 1061109567.000000000000000 ...
result:
wrong answer In case 1, expected '1906.022744343873', but found '1061109567.000000000000', error '0.999998203746'.