QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#185419#5145. Shortest PathPhantomThresholdWA 265ms323232kbC++202.9kb2023-09-22 02:22:202023-09-22 02:22:21

Judging History

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

  • [2023-09-22 02:22:21]
  • 评测
  • 测评结果:WA
  • 用时:265ms
  • 内存:323232kb
  • [2023-09-22 02:22:20]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define int long long
using namespace std;

const int maxn = 2050;
const int mod  = 998244353;
const int inv2 = (mod+1)>>1;
const int inf  = 1e15;
inline void down(int &a,const int &b){ if(a>b)a=b; }

vector< pair<int,int> >E[maxn];
int n,m,X;

int d1[10005][maxn],dn[10005][maxn];
int solve()
{
	ll U=min((ll)X,10000ll);
	for(int i=1;i<=n;i++)
		d1[0][i]=dn[0][i]=inf;
	d1[0][1]=0,dn[0][n]=0;
	
	int ret=0;
	
	for(int t=1;t<=U;t++)
	{
		for(int i=1;i<=n;i++) d1[t][i]=inf;
		for(int i=1;i<=n;i++)
		{
			for(auto [j,c]:E[i]) 
				down(d1[t][j],d1[t-1][i]+c);
		}
		
		for(int i=1;i<=n;i++) dn[t][i]=inf;
		for(int i=1;i<=n;i++)
		{
			for(auto [j,c]:E[i]) 
				down(dn[t][j],dn[t-1][i]+c);
		}
		
		if(d1[t][n]!=inf) ret+=d1[t][n]%mod;
		
	//	if(U-t<=10) cerr<<t<<" : "<<d1[n]<<endl;
	}
	return ret%mod;
}
struct line
{
	int x,y,k,t;
	friend inline bool operator <(const line &k1,const line &k2)
	{
		return k1.k>k2.k;
	}
};
vector<line>V[2];
//map< line,int >S;
line S[maxn<<4]; int sl,sr;

int calct(line k1,line k2)
{
	assert(k1.k>=k2.k);
	// k1.k>=k2.k
	int l=0,r=X/2+1;
	while(l<=r)
	{
		int mid=(l+r)>>1;
		if( k1.y+k1.k*(mid-k1.x) >= k2.y+k2.k*(mid-k2.x) ) r=mid-1;
		else l=mid+1;
	}
	return r+1;
}

int cal(const int ty)
{
	int l= (ty==0?10002/2:10001/2),r= (X%2==ty)?X/2:(X-1)/2;
	if(l>r) return 0;
	
	for(auto &x:V[ty])
	{
		x.k<<=1;
		x.x/=2;
	}
	
	sort(V[ty].begin(),V[ty].end());
	sl=1,sr=0;
	for(auto x:V[ty])
	{
		if(sl<=sr) S[sr].t= calct(S[sr],x);
		S[++sr]=x;
		while(sl+2<=sr && S[sr-2].t>=S[sr-1].t)
		{
			sr--;
			S[sr]=S[sr+1];
			S[sr-1].t=calct(S[sr-1],S[sr]);
		}
	}
	
	int ret=0;
	while(l<=r)
	{
		while(sl<sr && S[sl].t<=l)
		{
			sl++;
		}
		
		int nex=min(r, sl+1<=sr ? S[sl].t-1 : inf );
		//upd l
		
		//assert(!S.empty());
		if(sl<=sr)
		{
			line now= S[sl];
			ret+= (nex-l+1)%mod*inv2%mod*( (now.y+(l-now.x)*now.k%mod + now.y+(nex-now.x)*now.k%mod)%mod )%mod;
		}
		l=nex+1;
	}
	
	return ret%mod;
}
int calc()
{
	if(10000>=X) return 0;
	
	V[0].clear(); V[1].clear();
	for(int i=1;i<=n;i++) for(auto [j,c]:E[i])
	{
		int temp=inf;
		for(int t=0;t<=10000;t++) temp=min(temp, d1[t][i]+dn[10000-t][i]);
		V[0].emplace_back( 10000,temp,c,0 );
		
		temp=inf;
		for(int t=0;t<=9999;t++) temp=min(temp, d1[t][i]+dn[9999-t][i]);
		V[1].emplace_back( 9999,temp,c,0 );
		
	}
	int c0= cal(0), c1=cal(1);
	return c0+c1;
}

signed main()
{
	ios_base::sync_with_stdio(false); ////////////////////////////////////////
	cin.tie(0);
	
	ll Tcase; cin>>Tcase;
	while(Tcase--)
	{
		cin>>n>>m>>X;
		for(int i=1;i<=n;i++)
		{
			vector<pair<int,int> >_;
			E[i].swap(_);
		}
		for(int i=1;i<=m;i++)
		{
			ll x,y,w; cin>>x>>y>>w;
			E[x].emplace_back(y,w);
			E[y].emplace_back(x,w);
		}
		int ret= solve();
		
		ret+= calc();
		
		cout<<(long long)(ret%mod)<<'\n';
	}
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 265ms
memory: 323172kb

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
351280472
47725039
58483482
115858544
177378789
656019644
858116309
374929427
38761681
633010531
327200256
696693112
919354187
122684249
865793975
91541737
248634956
858185224
374201737
455984810
284991806
322357914
936175240
514668426
407812429
80469271
349575161
419773408
50182...

result:

wrong answer 3rd numbers differ - expected: '0', found: '351280472'