QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#251625 | #7775. 【模板】矩阵快速幂 | zhouhuanyi | 0 | 362ms | 1129564kb | C++14 | 2.0kb | 2023-11-14 22:01:11 | 2023-11-14 22:01:12 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<vector>
#define M 200000
#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: 7ms
memory: 68140kb
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
Wrong Answer
Test #7:
score: 15
Accepted
time: 295ms
memory: 1127964kb
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: 0
Accepted
time: 256ms
memory: 1129564kb
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 613575042 -1 416269325 -1 387291578 -1 980556870 -1 491367967 -1 221793101 -1 191668085 -1 356035653 -1 428450970 -1 964149805 -1 511723806 -1 423081033 -1 947783979 -1 325795034 -1 115778037 -1 86469999 -1 111666379 -1 386592847 -1 223100328 -1 381885001 -1 23001328 -1 84087613 -1 517941041 -1 9...
result:
ok 300 numbers
Test #9:
score: 0
Accepted
time: 248ms
memory: 1128208kb
input:
2 1 300 598 7877597936928589688789427798322599997378688496694695996269389696 1 2 866412995946330002 2 1 866412995946330002 2 3 866412995946330002 3 2 866412995946330002 3 4 866412995946330002 4 3 866412995946330002 4 5 866412995946330002 5 4 866412995946330002 5 6 866412995946330002 6 5 866412995946...
output:
708443714 -1 708438498 -1 708433282 -1 708428066 -1 708422850 -1 708417634 -1 708412418 -1 708407202 -1 708401986 -1 708396770 -1 708391554 -1 708386338 -1 708381122 -1 708375906 -1 708370690 -1 708365474 -1 708360258 -1 708355042 -1 708349826 -1 708344610 -1 708339394 -1 708334178 -1 708328962 -1 7...
result:
ok 300 numbers
Test #10:
score: 0
Accepted
time: 275ms
memory: 1128980kb
input:
2 1 300 598 74686617152792803 1 2 920869599353968456 2 1 920869599353968456 2 3 920869599353968456 3 2 920869599353968456 3 4 920869599353968456 4 3 920869599353968456 4 5 920869599353968456 5 4 920869599353968456 5 6 920869599353968456 6 5 920869599353968456 6 7 920869599353968456 7 6 9208695993539...
output:
-1 537762223 -1 537752459 -1 537742695 -1 537732931 -1 537723167 -1 537713403 -1 537703639 -1 537693875 -1 537684111 -1 537674347 -1 537664583 -1 537654819 -1 537645055 -1 537635291 -1 537625527 -1 537615763 -1 537605999 -1 537596235 -1 537586471 -1 537576707 -1 537566943 -1 537557179 -1 537547415 -...
result:
ok 300 numbers
Test #11:
score: -15
Wrong Answer
time: 362ms
memory: 183132kb
input:
2 40 120 238 7647979978895986883485788838258737687493899697379499657768989994 1 2 940784508355800649 2 1 940784508355800649 2 3 940784508355800649 3 2 940784508355800649 3 4 940784508355800649 4 3 940784508355800649 4 5 940784508355800649 5 4 940784508355800649 5 6 940784508355800649 6 5 94078450835...
output:
383704267 -1 383701847 -1 383699427 -1 383697007 -1 383694587 -1 383692167 -1 383689747 -1 383687327 -1 383684907 -1 383682487 -1 383680067 -1 383677647 -1 383675227 -1 383672807 -1 383670387 -1 383667967 -1 383665547 -1 383663127 -1 383660707 -1 383658287 -1 383655867 -1 383653447 -1 383651027 -1 3...
result:
wrong answer 327th numbers differ - expected: '382559229', found: '940863848'
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%