QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#251609 | #7775. 【模板】矩阵快速幂 | zhouhuanyi | 0 | 1ms | 4840kb | C++14 | 2.0kb | 2023-11-14 21:46:47 | 2023-11-14 21:46:47 |
answer
#include<iostream>
#include<cstdio>
#include<vector>
#define M 800
#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=m+n;
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>m) 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: 1ms
memory: 4840kb
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:
-1 -1 -1 -1 454736243 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 485665540 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -...
result:
wrong answer 1st numbers differ - expected: '395495792', found: '-1'
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%