QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#251611 | #7775. 【模板】矩阵快速幂 | zhouhuanyi | 0 | 3ms | 9948kb | C++14 | 2.0kb | 2023-11-14 21:47:18 | 2023-11-14 21:47:18 |
answer
#include<iostream>
#include<cstdio>
#include<vector>
#define M 1600
#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>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: 0ms
memory: 6128kb
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
Wrong Answer
Test #7:
score: 15
Accepted
time: 3ms
memory: 9868kb
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:
-1 313446627 -1 313436465 -1 313426303 -1 313416141 -1 313405979 -1 313395817 -1 313385655 -1 313375493 -1 313365331 -1 313355169 -1 313345007 -1 313334845 -1 313324683 -1 313314521 -1 313304359 -1 313294197 -1 313284035 -1 313273873 -1 313263711 -1 313253549 -1 313243387 -1 313233225 -1 313223063 -...
result:
ok 300 numbers
Test #8:
score: -15
Wrong Answer
time: 2ms
memory: 9948kb
input:
2 1 300 598 9284745978997975899894787995823975998931999649789777849997467689 1 2 946893593823801228 2 1 946893593823801228 2 3 761384824565158999 3 2 761384824565158999 3 4 642721010434291429 4 3 642721010434291429 4 5 936762490761905983 5 4 936762490761905983 5 6 785485094128355256 6 5 785485094128...
output:
-1 811123420 -1 352635938 -1 62476426 -1 394559953 -1 642433638 -1 111677007 -1 818614579 -1 721800382 -1 533033934 -1 807551004 -1 93943240 -1 742363055 -1 7639883 -1 122713526 -1 649759117 -1 359269314 -1 123283929 -1 137028632 -1 710598701 -1 608201609 -1 986380524 -1 786285044 -1 958956707 -1 18...
result:
wrong answer 2nd numbers differ - expected: '613575042', found: '811123420'
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%