QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#658706 | #7005. Rikka with Consistency | FreeTimeLove | AC ✓ | 140ms | 6780kb | C++14 | 4.1kb | 2024-10-19 17:25:54 | 2024-10-19 17:25:54 |
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<<3];
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);
}
}
I=(i+1)>>1,J=(j)>>1;
if(I>0&&J<n&&((i&1)||(j&1)||h[I]==h[J])){
if(!K[I]&&!(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]*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],mind)+gt((LD)mind/K[J+1],mind);
add(id,inc(ni,nj),w);
}
}
}
}
Dij();
printf("%.15Lf\n",d[inc(n+n,0)]);
}
re 0;
}
/*
1
6
0 8 0 9 3 5 0
1
12
0 12 13 1 14 4 15 6 6 14 9 10 0
1
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
*/
}signed main(){re FRTMLV::main();}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3992kb
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: 0
Accepted
time: 55ms
memory: 6488kb
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:
1906.022744343872653 1873.235902058971677 2645.063883550955734 541.334373575637191 1235.789070575067080 1951.673466582071729 1213.924537986642280 2017.586964700495137 312.764409849808348 3422.789227031028009 138.614373840089229 2149.988607593458737 1046.398399027540115 47.235496542825359 2511.302033...
result:
ok 500 cases
Test #3:
score: 0
Accepted
time: 139ms
memory: 6780kb
input:
500 43 0 6 6 1 1 1 6 1 1 5 1 5 6 5 6 1 5 5 6 6 5 5 6 1 5 6 1 6 5 5 5 6 6 6 1 1 6 6 5 1 5 6 1 0 50 0 18 39 18 28 18 18 18 28 47 28 28 48 8 8 39 48 8 39 19 47 19 19 18 48 20 28 28 18 20 20 39 48 8 8 39 48 20 20 20 8 8 18 19 8 8 8 18 8 48 0 43 0 25 29 25 44 32 32 50 50 32 29 44 25 25 25 25 32 44 29 24 ...
output:
252.206597642424804 2006.435281721252624 1567.038925605685539 247.414560115704416 2355.132191397364861 2039.238972205762331 585.478974238961646 1706.290065834044634 2455.778326124428040 1429.668304029657982 386.224743513894010 2328.353187315603252 231.799816853834118 1613.936196696445011 1209.083690...
result:
ok 500 cases
Test #4:
score: 0
Accepted
time: 140ms
memory: 6724kb
input:
500 42 0 27 22 28 20 31 17 33 14 34 13 35 11 42 8 44 4 49 2 50 1 23 3 47 5 46 7 43 9 41 10 38 12 36 16 32 18 30 19 29 23 23 0 44 0 23 23 27 20 32 18 36 15 38 11 44 8 45 6 47 4 48 3 23 1 50 5 46 7 43 9 42 12 41 13 40 14 37 16 35 17 33 19 31 21 29 22 28 0 48 0 48 3 46 5 44 7 41 9 39 11 37 13 35 15 32 ...
output:
19134.183214273577279 24340.101477166196858 4598.013576117175996 35163.594345442836953 19719.494679706962449 24330.979818524220851 17290.096811584820481 31672.450581090092690 30612.789045852057150 21650.286891939607296 26014.044881173541711 10391.561513884478749 25028.333677920774747 36818.649179677...
result:
ok 500 cases