QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#251624#7775. 【模板】矩阵快速幂zhouhuanyi0 4ms67460kbC++142.0kb2023-11-14 22:00:322023-11-14 22:00:33

Judging History

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

  • [2023-11-14 22:00:33]
  • 评测
  • 测评结果:0
  • 用时:4ms
  • 内存:67460kb
  • [2023-11-14 22:00:32]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<vector>
#define M 40000
#define N 400
#define mod 998244353
using namespace std;
const int inv2=(mod+1)>>1;
const __int128 inf=(__int128)(1e30);
long long read()
{
	char c=0;
	long long sum=0;
	while (c<'0'||c>'9') c=getchar();
	while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
	return sum;
}
int MD(int x)
{
	return x>=mod?x-mod:x;
}
int MD2(int x)
{
	return x<0?x+mod:x;
}
struct reads
{
	int num;
	long long data;
};
int S,T,n,m,maxn,k,res;
__int128 dp[M+1][N+1];
vector<reads>E[N+1];
void add(int x,int y,long long z)
{
	E[x].push_back((reads){y,z});
	return;
}
int main()
{
	string s;
	int x,y;
	long long z;
	bool op;
	S=read(),T=read();
	while (T--)
	{
		n=read(),m=read(),cin>>s,k=op=res=0,maxn=n*m;
		for (int i=1;i<=n;++i) E[i].clear();
		for (int i=1;i<=m;++i) x=read(),y=read(),z=read(),add(x,y,z);
		for (int i=0;i<s.length();++i)
		{
			if (!op)
			{
				k=k*10+s[i]-'0';
				if (k>maxn) op=1;
			}
			res=(10ll*res+s[i]-'0')%mod;
		}
		for (int i=0;i<=maxn+2;++i)
			for (int j=1;j<=n;++j)
				dp[i][j]=inf;
		dp[0][1]=0;
		for (int i=1;i<=maxn+2;++i)
			for (int j=1;j<=n;++j)
				for (int t=0;t<E[j].size();++t)
					dp[i][E[j][t].num]=min(dp[i][E[j][t].num],dp[i-1][j]+E[j][t].data);
	    if (!op)
		{
			for (int i=1;i<=n;++i)
			{
				if (dp[k][i]==inf) printf("-1 ");
				else printf("%d ",(int)(dp[k][i]%mod));
			}
		}
		else
		{
			if (((s[(int)(s.length())-1]-'0')&1)==(maxn&1))
			{
				for (int i=1;i<=n;++i)
				{
					if (dp[maxn][i]==inf) printf("-1 ");
					else printf("%d ",(int)(MD(dp[maxn][i]%mod+1ll*((dp[maxn+2][i]-dp[maxn][i])%mod)*MD2(res-maxn)%mod*inv2%mod)));
				}
			}
			else
			{
				for (int i=1;i<=n;++i)
				{
					if (dp[maxn-1][i]==inf) printf("-1 ");
					else printf("%d ",(int)(MD(dp[maxn-1][i]%mod+1ll*((dp[maxn+1][i]-dp[maxn-1][i])%mod)*MD2(res-(maxn-1))%mod*inv2%mod)));
				}
			}
		}
		puts("");
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 67460kb

input:

1
1
100 101 899539897889989959
74 35 910832669819965536
35 85 910832669819965536
85 88 910832669819965536
88 30 910832669819965536
30 58 910832669819965536
58 60 910832669819965536
60 34 910832669819965536
34 8 910832669819965536
8 67 910832669819965536
67 89 910832669819965536
89 32 910832669819965...

output:

358672801 457364331 457364333 457364289 457364243 457364339 457364304 457364282 457364295 457364305 457364273 457364323 457364303 457364250 457364332 457364313 457364297 457364311 457364244 358672800 457364336 457364271 457364248 457364315 457364322 457364320 457364307 457364269 457364293 457364278 ...

result:

wrong answer 1st numbers differ - expected: '395495792', found: '358672801'

Subtask #2:

score: 0
Runtime Error

Test #7:

score: 0
Runtime Error

input:

2
1
300 598 8179377797889487867988994778539839593376697796496698959964978969
1 2 977880533270721156
2 1 977880533270721156
2 3 977880533270721156
3 2 977880533270721156
3 4 977880533270721156
4 3 977880533270721156
4 5 977880533270721156
5 4 977880533270721156
5 6 977880533270721156
6 5 977880533270...

output:


result:


Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Skipped

Dependency #3:

0%