QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#882194#5145. Shortest PathqwqUwU_WA 2ms7940kbC++142.4kb2025-02-04 21:56:112025-02-04 21:56:13

Judging History

This is the latest submission verdict.

  • [2025-02-04 21:56:13]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 7940kb
  • [2025-02-04 21:56:11]
  • Submitted

answer

#include<bits/stdc++.h>
#define pb push_back
#define P make_pair
#define fi first
#define se second
#define bit(s,x) (((s)>>(x))&1)
#define pnp(s) __builtin_popcountll(s)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
typedef long long ll; 
typedef unsigned long long ull;
typedef pair<int,int> pii;
inline ll read(){
	ll x=0,f=1,c=getchar();
	while(c<'0'||c>'9')f=(c=='-'?-1:1),c=getchar();
	while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
const int N=2002;
const int mod=998244353;
const ll INF=1ll<<60;
int n,m,K;
vector<pii>G[N];
ll f[N<<2][N],g[N<<2][N],ans;
inline void ck(ll &x,ll y){y<x&&(x=y);}
typedef pair<ll,ll> pll;
inline bool cr(pll A,pll B,pll C){
	return (__int128)(B.fi-A.fi)*(C.se-A.se)>(__int128)(C.fi-A.fi)*(B.se-A.se);
}
inline void ad(pll A,ll L,ll R){
	if(L>R)return;
	ll k=A.fi,b=A.se%mod;
	ans=(ans + (R-L+1)*b + (L+R)*(R-L+1)/2%mod*k)%mod;
}
inline void solve(vector<pll>A,ll K){
	sort(A.begin(),A.end());
	rep(i,1,(int)A.size()-1)if(A[i].fi==A[i-1].fi)swap(A[i],A.back()),A.pop_back(),--i;
	static pll st[N];
	int m=A.size(),tp=0;
	st[tp=1]=A[0];
	rep(i,1,m-1){
		for(;tp>1&&!cr(st[tp-1],st[tp],A[i]);--tp);
		st[++tp]=A[i];
	}
	ll lst=1;
	for(;tp>1;--tp){
		pll A=st[tp],B=st[tp-1];
		if(A.se>=B.se)continue;
		ll k=min(K,(B.se-A.se)/(A.fi-B.fi));
		ad(A,lst,k); lst=k+1;
	}
	ad(A[0],lst,K);
}
inline void solve(){
	n=read(),m=read(),K=read();
	rep(i,1,n)G[i].clear();
	rep(i,1,m){
		int u=read(),v=read(),w=read();
		G[u].pb(P(v,w)),G[v].pb(P(u,w));
	}
	int T=4*n+1;
	rep(i,0,T)rep(j,1,n)f[i][j]=g[i][j]=INF;
	f[0][1]=g[0][n]=0;
	rep(i,1,T)rep(j,1,n)for(pii A:G[j]){
		ck(f[i][A.fi],f[i-1][j]+A.se);
		ck(g[i][A.fi],g[i-1][j]+A.se);
	}
	ans=0;
	rep(i,1,min(T,K))if(f[i][n]<INF)ans+=f[i][n],ans%=mod;
	if(K<=T){printf("%lld\n",ans);return;}
	vector<pll>ve0,ve1;
	rep(i,1,n){
		ll a=INF,b=INF,c=INF;
		for(pii A:G[i])c=min(c,(ll)A.se);
		rep(j,0,T-1)a=min(a,f[j][i]+g[T-1-j][i]);
		rep(j,0,T)b=min(b,f[j][i]+g[T-j][i]);
		if(a<INF)ve0.pb(P(2*c,a));
		if(b<INF)ve1.pb(P(2*c,b));
	}
	if(ve0.size())solve(ve0,(K-T+1)/2);
	if(ve1.size())solve(ve1,(K-T)/2);
	printf("%lld\n",ans);
}
int main() {
    //freopen("data.in", "r", stdin);
    //freopen("myans.out","w",stdout);
	int T=read(); while(T--)solve();
    return 0;
}

詳細信息

Test #1:

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

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: 5884kb

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
38769601
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 11th numbers differ - expected: '38761681', found: '38769601'