QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#735749 | #9569. Subway | as_lyr | WA | 48ms | 308628kb | C++14 | 2.1kb | 2024-11-11 21:32:13 | 2024-11-11 21:32:16 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=410000;
const ll INF=1e18;
int n,m;
int a[N],b[N];
int t,to[N],id[N];
vector <pair<int,int>> e[N];
vector <int> v[N];
deque <int> st[N];
int stp[N];
ll dis[N];
bool vis[N];
ll ans[N];
inline ll calc(int x,int y){
return dis[x]+1ll*a[id[y]]*b[id[x]];
}
inline double slope(int xa,int xb,int y){
if(b[id[xa]]==b[id[xb]])
return INF+(dis[xb]-dis[xa]);
return 1.0*(dis[xb]-dis[xa])/(b[id[xb]]-b[id[xa]]);
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
scanf("%d",&a[i]);
for(int i=1;i<=m;i++)
scanf("%d",&b[i]);
for(int i=1;i<=m;i++){
int siz;
scanf("%d",&siz);
int lst;
{
int x;
scanf("%d",&x);
t++,to[t]=x,id[t]=i;
v[x].push_back(t);
lst=t;
}
for(int j=2;j<=siz;j++){
int w,x;
scanf("%d%d",&w,&x);
t++,to[t]=x,id[t]=i;
e[lst].push_back(make_pair(t,w));
v[x].push_back(t);
lst=t;
}
}
for(int i=1;i<=n;i++){
sort(v[i].begin(),v[i].end(),[](const int x,const int y){
return a[id[x]]<a[id[y]];
});
}
priority_queue <pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq;
for(int i=1;i<=t;i++)
if(to[i]==1)
pq.push(make_pair(0,i));
else
dis[i]=INF;
for(int i=1;i<=n;i++)
ans[i]=INF;
while(pq.empty()==0){
int x=pq.top().second;
pq.pop();
if(vis[x])
continue;
vis[x]=1;
int i=to[x];
ans[i]=min(ans[i],dis[x]);
while(stp[i]<(int)v[i].size()&&vis[v[i][stp[i]]])
stp[i]++;
if(stp[i]<(int)v[i].size()){
int y=v[i][stp[i]];
while(st[i].empty()>1&&slope(st[i][st[i].size()-2],st[i].back(),y)<slope(st[i].back(),x,y))
st[i].pop_back();
st[i].push_back(x);
while(st[i].size()>1&&calc(st[i][0],y)>calc(st[i][1],y))
st[i].pop_front();
if(calc(st[i][0],y)<dis[y])
pq.push(make_pair(dis[y]=calc(st[i][0],y),y));
}
for(auto pr:e[x]){
int y=pr.first,z=pr.second;
if(dis[x]+z<dis[y])
pq.push(make_pair(dis[y]=dis[x]+z,y));
}
}
for(int i=2;i<=n;i++)
printf("%lld ",ans[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 46ms
memory: 306644kb
input:
6 3 1 5 1 5 5 1 3 1 2 2 3 3 3 5 1 2 1 4 3 3 4 5 4 6
output:
2 5 21 14 18
result:
ok 5 number(s): "2 5 21 14 18"
Test #2:
score: 0
Accepted
time: 40ms
memory: 306576kb
input:
6 3 1 5 1 5 5 1 5 1 2 2 100 3 100 6 1 4 5 1 100 2 4 3 100 5 1 4 2 3 1 5
output:
2 31 43 37 136
result:
ok 5 number(s): "2 31 43 37 136"
Test #3:
score: 0
Accepted
time: 48ms
memory: 306612kb
input:
5 9 278281 70119 511791 834898 25300 63487 609134 236836 394497 835557 287345 579404 879128 636344 306393 569430 152565 47119 2 3 823004250 4 2 1 25427550 3 2 1 15849621 3 2 1 701911826 5 3 5 679672631 3 907176714 2 2 1 817370554 2 2 3 697987914 2 2 4 873900795 2 2 1 814305954 5
output:
817370554 15849621 80811085745 701911826
result:
ok 4 number(s): "817370554 15849621 80811085745 701911826"
Test #4:
score: 0
Accepted
time: 48ms
memory: 308628kb
input:
5 10 436148 103565 528276 212202 680282 92724 609031 560815 80390 406327 546832 581372 731920 348686 791433 98906 112247 118131 361076 724950 4 1 213029090 4 415633732 5 581145231 3 2 4 306227294 2 2 1 713116112 4 2 3 99672714 5 2 3 975143846 1 5 4 249118026 5 689334413 1 597093740 2 553624319 3 3 4...
output:
597093740 765908995 213029090 628662822
result:
ok 4 number(s): "597093740 765908995 213029090 628662822"
Test #5:
score: 0
Accepted
time: 47ms
memory: 306576kb
input:
3 5 696710 837216 390019 431068 960618 589388 829806 692481 154511 282620 2 1 711629163 3 2 1 781784306 3 2 1 686636041 3 2 3 794790206 2 2 1 844212542 2
output:
844212542 686636041
result:
ok 2 number(s): "844212542 686636041"
Test #6:
score: 0
Accepted
time: 43ms
memory: 306864kb
input:
3 8 344877 101098 328614 735002 476606 635558 573861 261083 964379 333960 25186 276560 258996 683650 765559 582374 2 3 838262394 1 2 2 863940316 3 2 2 476918371 3 3 3 320092619 1 400754003 2 3 3 150885055 2 90507792 1 2 3 190275693 2 2 2 600234969 3 2 2 679446528 3
output:
400754003 29224357199
result:
ok 2 number(s): "400754003 29224357199"
Test #7:
score: -100
Wrong Answer
time: 48ms
memory: 306612kb
input:
50 52 895514 29433 851800 887860 340384 95967 506578 666268 850660 602220 717255 242039 34055 752012 248567 170469 505996 823344 143369 390858 112988 892365 15368 617804 351619 557340 788960 990487 283825 272924 24678 130649 341049 980236 558990 254726 682005 963825 953074 603477 706464 340694 23541...
output:
632126151 479346918 492618840 3695787776 22624579200 174047740 416387993526 21429733469 15831777447 203893499 522142321620 977566721 279122223 30345963113 804573598 73397618725 6389037892 224856032596 416404080694 75356833904 69909552850 4504114918 13173874327 1104455938 278587376156 136977429637 22...
result:
wrong answer 25th numbers differ - expected: '275720760247', found: '278587376156'