QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#414107 | #3788. Funny Car Racing | 23lpx | 0 | 115ms | 22504kb | C++20 | 1.8kb | 2024-05-18 15:25:14 | 2024-05-18 15:25:14 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+9;
#define int long long
struct PII{
int x,sum;
friend bool operator<(PII A,PII B)
{
return A.sum>B.sum;
}
};
int h[N],e[N],ne[N],w[N],a[N],b[N],idx=1,cnt=1,n,m,ss,tt,st[N],d[N];
void add(int u,int v,int A,int B,int T)
{
e[idx]=v;
w[idx]=T;
a[idx]=A;
b[idx]=B;
ne[idx]=h[u];
h[u]=idx++;
// printf("idx=%lld u=%lld v=%lld h=%lld\n",idx,u,v,h[u]);
}
void djstla()
{
for(int i=0;i<=n;i++){d[i]=1e9;st[i]=0;}
priority_queue<PII>q;
q.push({ss,0});
d[ss]=0;
while(q.size())
{
PII t=q.top();
q.pop();
// printf("t.x=%lld dis=%lld\n",t.x,t.sum);
if(st[t.x])continue;
st[t.x]=1;
int num=t.x,dis=t.sum;
// printf("h=%lld \n",h[num]);
for(int i=h[num];i;i=ne[i])
{
int y=e[i];
// printf("i=%lld y=%lld \n",i,y);
if(!st[y])
{
int xx=dis,aa=a[i],bb=b[i];
int yy=w[i],res=1e9;
if(xx%(aa+bb)<=aa)//开门
{
int tt=xx/(aa+bb)*(aa+bb)+aa;
if((xx+yy)<=tt)//剩余时间可以通过
{
res=xx+yy;
}
else
{
tt+=(aa+bb);
if((xx+aa+bb-xx%(aa+bb)+yy)<=tt)
{
res=xx+aa+bb-xx%(aa+bb)+yy;
}
}
}
else//关门
{
int tt=xx/(aa+bb)*(aa+bb)+aa+aa+bb;
xx=xx+aa+bb-xx%(aa+bb)+yy;
if(xx<=tt)res=xx;
}
if((res)<d[y])
{
d[y]=res;
q.push({y,d[y]});
}
}
}
}
printf("Case %lld: %lld\n",cnt++,d[tt]);
}
void solve()
{
for(int i=1;i<=m*3;i++)ne[i]=0,h[i]=0;
idx=1;
while(m--)
{
int u,v,a,b,t;
cin>>u>>v>>a>>b>>t;
add(u,v,a,b,t);
add(v,u,a,b,t);
}
djstla();
}
signed main()
{
while(cin>>n>>m>>ss>>tt)
{
solve();
}
return 0;
}
//3 2 1 3
//1 2 5 6 3
//2 3 7 7 6
//3 2 1 3
//1 2 5 6 3
//2 3 9 5 6
详细
Test #1:
score: 0
Wrong Answer
time: 115ms
memory: 22504kb
input:
155 9507 117 14 19 18 2 123 1 100 97 4 155 3 121 120 1 140 1 5 8 1 121 1 69 66 2 107 2 151 150 2 190 1 68 69 1 101 1 61 60 2 126 1 124 127 2 160 3 59 55 5 133 4 66 67 1 189 1 94 96 2 108 2 65 63 2 181 2 44 48 1 130 1 28 29 1 180 1 5 6 1 107 1 29 28 1 120 1 142 140 4 152 2 46 45 2 113 1 85 88 6 163 3...
output:
Case 1: 158 Case 2: 689 Case 3: 847 Case 4: 172 Case 5: 445 Case 6: 379 Case 7: 154 Case 8: 429 Case 9: 343 Case 10: 176 Case 11: 254 Case 12: 220 Case 13: 835 Case 14: 514 Case 15: 167 Case 16: 180 Case 17: 264 Case 18: 355 Case 19: 347 Case 20: 194 Case 21: 192 Case 22: 406 Case 23: 561 Case 24: 3...
result:
wrong answer 1st lines differ - expected: 'Case 1: 249', found: 'Case 1: 158'