QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#507743#5145. Shortest PathyyyyxhWA 1ms3696kbC++142.5kb2024-08-06 20:38:392024-08-06 20:38:55

Judging History

你现在查看的是最新测评结果

  • [2024-08-06 20:38:55]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3696kb
  • [2024-08-06 20:38:39]
  • 提交

answer

#include <cstdio>
#include <algorithm>
using namespace std;
int read(){
	char c=getchar();int x=0;
	while(c<48||c>57) c=getchar();
	do x=x*10+(c^48),c=getchar();
	while(c>=48&&c<=57);
	return x;
}
const int L=8003,N=2003,M=5003;
const int P=998244353;
typedef long long ll;
typedef __int128 lll;
const ll INF=0x3f3f3f3f3f3f3f3f;
int n,m,k,rk,lim;
ll Fs[L][N],Ft[L][N];
ll Fe[N],Fo[N];
inline void chmn(ll &x,ll v){if(x>v) x=v;}
int eu[M],ev[M],ew[M];
struct Line{
	ll a,b; // a * x + b
	friend bool operator<(const Line x,const Line y){
		if(x.a^y.a) return x.a>y.a;
		return x.b<y.b;
	}
}w[N];
int stk[N],tp;
inline bool check(int x,int y,int z){
	return (lll)(w[z].b-w[y].b)*(w[x].a-w[z].a)<=(lll)(w[z].b-w[x].b)*(w[y].a-w[z].a);
}
int S(int l,int r){return ((ll)(l+r)*(r-l+1)>>1)%P;}
int calc(int lim){
	sort(w+1,w+rk+1);
	int las=0,res=0;
	tp=0;
	for(int i=1;i<=rk;++i){
		if(tp&&w[stk[tp]].a==w[i].a) continue;
		while(tp>1&&check(stk[tp-1],stk[tp],i)) --tp;
		stk[++tp]=i;
	}
	for(int i=1;i<=tp;++i){
		ll sp=i==tp?lim:(w[stk[i+1]].b-w[stk[i]].b)/(w[stk[i]].a-w[stk[i+1]].a);
		if(sp>lim) sp=lim;
		res=(res+w[stk[i]].a%P*S(las+1,sp)+w[stk[i]].b%P*(sp-las))%P;
		las=sp;
		if(las==lim) break;
	}
	return res;
}
void solve(){
	n=read();m=read();k=read();lim=n<<2;
	for(int i=1;i<=m;++i) eu[i]=read(),ev[i]=read(),ew[i]=read();
	for(int x=0;x<=lim;++x)
		for(int i=1;i<=n;++i) Fs[x][i]=Ft[x][i]=INF;
	Fs[0][1]=Ft[0][n]=0;
	for(int x=0;x<lim;++x)
		for(int i=1;i<=m;++i){
			chmn(Fs[x+1][eu[i]],Fs[x][ev[i]]+ew[i]);
			chmn(Fs[x+1][ev[i]],Fs[x][eu[i]]+ew[i]);
			chmn(Ft[x+1][eu[i]],Ft[x][ev[i]]+ew[i]);
			chmn(Ft[x+1][ev[i]],Ft[x][eu[i]]+ew[i]);
		}
	int res=0;
	for(int i=1;i<=lim&&i<=k;++i) if(Fs[i][n]!=INF) res=(res+Fs[i][n])%P;
	if(Fs[lim][n]==INF&&Fs[lim-1][n]==INF){puts("0");return;}
	if(k<=lim){printf("%d\n",res);return;}
	for(int x=1;x<=n;++x) Fe[x]=Fo[x]=INF;
	for(int i=0;i<=lim;++i)
		for(int x=1;x<=n;++x) chmn(Fe[x],Fs[i][x]+Ft[lim-i][x]);
	for(int i=0;i<lim;++i)
		for(int x=1;x<=n;++x) chmn(Fo[x],Fs[i][x]+Ft[lim-i-1][x]);
	rk=0;
	for(int i=1;i<=m;++i){
		if(Fe[eu[i]]!=INF) w[++rk]=(Line){2*ew[i],Fe[eu[i]]};
		if(Fe[ev[i]]!=INF) w[++rk]=(Line){2*ew[i],Fe[ev[i]]};
	}
	res+=calc((k-lim)>>1);
	if(res>=P) res-=P;
	rk=0;
	for(int i=1;i<=m;++i){
		if(Fo[eu[i]]!=INF) w[++rk]=(Line){2*ew[i],Fo[eu[i]]};
		if(Fo[ev[i]]!=INF) w[++rk]=(Line){2*ew[i],Fo[ev[i]]};
	}
	res+=calc((k-lim+1)>>1);
	if(res>=P) res-=P;
	printf("%d\n",res);
}
int main(){
	int tc=read();
	while(tc--) solve();
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3676kb

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: 1ms
memory: 3696kb

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:

wrong answer 69th numbers differ - expected: '494626913', found: '494626733'