QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#335941 | #5145. Shortest Path | C1942huangjiaxu | WA | 2ms | 8104kb | C++14 | 1.8kb | 2024-02-24 10:12:17 | 2024-02-24 10:12:19 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=2005,P=998244353;
typedef long long ll;
const ll inf=2e18;
int T,n,m,x,ans;
vector<pair<int,int> >e[N];
ll f[N<<2][N],g[N<<2][N],F0[N],F1[N];
vector<pair<ll,ll> >t0,t1;
ll calc(vector<pair<ll,ll> >&t,ll k,int o){
k=2*k+o;
ll res=inf;
for(auto [x,y]:t)res=min(res,x*k+y);
return res;
}
void solve(vector<pair<ll,ll> >&t,int o){
int nw=2*n+1-o,lim=x-o>>1;
while(nw<=lim){
ll v=calc(t,nw,o);
if(nw==lim){
ans=(ans+v)%P;
return;
}
int l=nw+1,r=lim;
ll d=calc(t,nw+1,o)-v;
while(l<r){
int mid=l+r+1>>1;
if(calc(t,mid,o)==v+d*(mid-nw))l=mid;
else r=mid-1;
}
int ln=l-nw+1;
ans=(ans+v%P*ln+d%P*(1ll*ln*(ln-1)/2%P))%P;
nw=l+1;
}
}
void solve(){
scanf("%d%d%d",&n,&m,&x);
for(int i=1;i<=n;++i)e[i].clear();
t0.clear(),t1.clear(),ans=0;
for(int i=1,x,y,z;i<=m;++i){
scanf("%d%d%d",&x,&y,&z);
e[x].push_back({y,z});
e[y].push_back({x,z});
}
for(int i=1;i<=n;++i){
F0[i]=F1[i]=inf;
for(int j=0;j<=4*n+1;++j)f[j][i]=g[j][i]=inf;
}
f[0][1]=g[0][n]=0;
for(int i=0;i<=n*4;++i)
for(int j=1;j<=n;++j)for(auto [x,y]:e[j]){
f[i+1][x]=min(f[i+1][x],f[i][j]+y);
g[i+1][x]=min(g[i+1][x],g[i][j]+y);
}
for(int i=1;i<=n;++i){
for(int j=0;j<=n*4;++j){
F0[i]=min(F0[i],f[j][i]+g[4*n-j][i]);
F1[i]=min(F1[i],f[j][i]+g[4*n+1-j][i]);
}
F1[i]=min(F1[i],f[n*4+1][i]+g[0][i]);
}
for(int i=1;i<=n;++i)for(auto [x,y]:e[i])if(x>i){
if(F0[i]<inf)t0.push_back({y,F0[i]-4ll*n*y});
if(F1[i]<inf)t1.push_back({y,F1[i]-(4ll*n+1)*y});
}
for(int i=1;i<=x&&i<=n*4;++i)if(f[i][n]<inf)ans=(ans+f[i][n])%P;
if(x<=n*4)return printf("%d\n",ans),void();
if(!t0.empty())solve(t0,0);
if(!t1.empty())solve(t1,1);
printf("%d\n",ans);
}
int main(){
scanf("%d",&T);
while(T--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 8104kb
input:
4 3 2 10 1 2 5 2 3 4 3 0 1000000000 3 3 100 1 2 3 1 3 4 2 3 5 4 6 1000000000 1 2 244 1 2 325 1 4 927 3 3 248 2 4 834 3 4 285
output:
125 0 15300 840659991
result:
ok 4 number(s): "125 0 15300 840659991"
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 6032kb
input:
400 4 7 850187899 1 2 83 1 2 24 3 1 23 2 3 80 3 3 65 1 2 55 2 4 31 4 7 297586795 3 4 54 1 1 66 2 2 75 1 3 68 1 4 27 1 4 29 2 3 96 5 7 217277444 3 3 9 3 4 36 2 2 77 5 5 38 3 3 6 1 2 18 1 2 23 5 6 379032278 5 5 96 4 3 92 3 2 49 4 3 44 1 4 19 1 1 18 5 6 534284598 5 1 59 1 2 2 3 3 55 2 2 24 5 4 34 2 4 7...
output:
191476186 406722183 0 0 58483482 28283780 177378789 419045862 858116309 0 38761681 719243295 0 696693112 919354187 122684249 865793975 197565273 248634956 0 374201737 455984810 284991806 322357914 0 514668426 407812429 555256220 0 419773408 989291360 743372489 0 716008724 0 189418326 244106015 41273...
result:
wrong answer 6th numbers differ - expected: '115858544', found: '28283780'