QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#401082 | #5145. Shortest Path | zhouhuanyi | WA | 1ms | 4128kb | C++14 | 3.5kb | 2024-04-27 21:36:53 | 2024-04-27 21:36:54 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#define N 4000
#define mod 998244353
using namespace std;
const long long inf=(long long)(1e18);
const int INF=(int)(1e9)+1;
int read()
{
char c=0;
int sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
void Adder(int &x,int d)
{
x+=d;
if (x>=mod) x-=mod;
return;
}
struct reads
{
int num,data;
};
struct points
{
int x;
long long y;
bool operator < (const points &t)const
{
return x!=t.x?x<t.x:y<t.y;
}
};
points tong[N+1],dque[N+1];
int T,n,m,t,top,ans,length,minn[N+1];
long long dp[N+1][N+1],dp2[N+1][N+1],sminn[2],sminn2[2];
vector<reads>E[N+1];
void add(int x,int y,int z)
{
minn[x]=min(minn[x],z),minn[y]=min(minn[y],z),E[x].push_back((reads){y,z}),E[y].push_back((reads){x,z});
return;
}
bool check(points a,points b,points c)
{
return (__int128)(b.y-a.y)*(c.x-a.x)>=(__int128)(c.y-a.y)*(b.x-a.x);
}
long long get(long long a,int b)
{
if (!b) return a>=0?INF:-INF;
else if (a>=0) return a/b+1;
else return -(-a-1)/b;
}
long long get2(long long a,int b)
{
if (!b) return a>=0?INF:-INF;
else if (a>=0) return a/b;
else return -(-a+b-1)/b;
}
void calc(int x)
{
long long l,r;
sort(tong+1,tong+length+1),top=0;
for (int i=1;i<=length;++i)
{
while (top>=2&&check(dque[top-1],dque[top],tong[i])) top--;
dque[++top]=tong[i];
}
for (int i=1;i<=top;++i)
{
l=0,r=x;
if (i+1<=top) l=max(l,get(dque[i].y-dque[i+1].y,dque[i+1].x-dque[i].x));
if (i-1>=1) r=min(r,get2(dque[i-1].y-dque[i].y,dque[i].x-dque[i-1].x));
if (l<=r)
{
Adder(ans,(r-l+1)*(dque[i].y%mod)%mod);
Adder(ans,(((r*(r+1)>>1)-((l*(l-1))>>1))%mod)*dque[i].x%mod);
}
}
return;
}
int main()
{
int x,y,z,d;
T=read();
while (T--)
{
n=read(),m=read(),t=read(),ans=0;
for (int i=1;i<=n;++i) E[i].clear(),minn[i]=INF;
for (int i=1;i<=m;++i) x=read(),y=read(),z=read(),add(x,y,z);
for (int i=0;i<=(n<<1);++i)
for (int j=1;j<=n;++j)
dp[i][j]=dp2[i][j]=inf;
dp[0][1]=dp2[0][n]=0;
for (int i=1;i<=(n<<1);++i)
for (int j=1;j<=n;++j)
for (int k=0;k<E[j].size();++k)
dp[i][j]=min(dp[i][j],dp[i-1][E[j][k].num]+E[j][k].data),dp2[i][j]=min(dp2[i][j],dp2[i-1][E[j][k].num]+E[j][k].data);
for (int i=0;i<=min(t,n<<1);++i)
if (dp[i][n]!=inf)
Adder(ans,dp[i][n]%mod);
if (t>=(n<<1)+1&&dp[(n<<1)-1][n]!=inf)
{
d=(t-(n<<1)-1)>>1,length=0;
for (int i=1;i<=n;++i)
if (minn[i]!=INF)
{
for (int op=0;op<=1;++op) sminn[op]=sminn2[op]=inf;
for (int j=0;j<=n;++j) sminn[j&1]=min(sminn[j&1],dp[j][i]-1ll*minn[i]*j),sminn2[j&1]=min(sminn2[j&1],dp2[j][i]-1ll*minn[i]*j);
if (min(sminn[0]+sminn2[1],sminn[1]+sminn2[0])+1ll*minn[i]*((n<<1)+1)<inf) tong[++length]=(points){minn[i]<<1,min(sminn[0]+sminn2[1],sminn[1]+sminn2[0])+1ll*minn[i]*((n<<1)+1)};
}
calc(d);
}
if (t>=(n<<1)+2&&dp[n<<1][n]!=inf)
{
d=(t-(n<<1)-2)>>1,length=0;
for (int i=1;i<=n;++i)
if (minn[i]!=INF)
{
for (int op=0;op<=1;++op) sminn[op]=sminn2[op]=inf;
for (int j=0;j<=n;++j) sminn[j&1]=min(sminn[j&1],dp[j][i]-1ll*minn[i]*j),sminn2[j&1]=min(sminn2[j&1],dp2[j][i]-1ll*minn[i]*j);
if (min(sminn[0]+sminn2[0],sminn[1]+sminn2[1])+1ll*minn[i]*((n<<1)+2)<inf) tong[++length]=(points){minn[i]<<1,min(sminn[0]+sminn2[0],sminn[1]+sminn2[1])+1ll*minn[i]*((n<<1)+2)};
}
calc(d);
}
printf("%d\n",ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4128kb
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: 0
Accepted
time: 1ms
memory: 3960kb
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 115858544 177378789 656019644 858116309 0 38761681 633010531 0 696693112 919354187 122684249 865793975 91541737 248634956 0 374201737 455984810 284991806 322357914 0 514668426 407812429 555256220 0 419773408 989291360 743372489 0 716008724 0 189418326 244106015 41273...
result:
ok 400 numbers
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 4028kb
input:
400 4 6 415388949 4 2 6853 4 3 5541 1 2 6273 4 4 8561 4 1 9638 4 2 8341 4 6 195566032 2 3 6344 1 1 7616 3 1 4823 4 1 647 4 4 7091 4 2 6307 4 6 720662513 3 3 4435 2 1 4448 4 3 3142 4 1 6670 2 4 5545 2 3 2990 5 7 806244066 3 2 3989 4 3 8157 5 2 612 3 5 8294 1 1 2114 3 4 2311 5 2 8825 5 6 894954332 4 1...
output:
392283147 970308579 491899881 0 495762954 10156057 664457753 0 575852185 134843393 933754264 590740253 0 490859785 724017823 957609109 0 622353894 279038091 426991125 0 637389724 0 75171267 749597224 258493187 250907837 497917111 886569508 828505392 68793449 224109727 139499076 786372001 894480753 4...
result:
wrong answer 286th numbers differ - expected: '248769754', found: '878182835'