QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#269392 | #7775. 【模板】矩阵快速幂 | 275307894a | 0 | 422ms | 1736032kb | C++14 | 2.1kb | 2023-11-29 16:24:35 | 2023-11-29 16:24:36 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=300+5,M=8e5+5,K=(1<<25)+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(time(0));
using LL=__int128;
void read(LL &x){
char c=Gc();x=0;
while(c<'0'||c>'9') c=Gc();
while(c>='0'&&c<='9') x=x*10+c-48,c=Gc();
}
int n,m,X[N*2],Y[N*2];ll Z[N*2];
LL f[N*N*2][N],k,g[N][N][N],dp[N*N][N];
void Solve(){
int i,j,h;scanf("%d%d",&n,&m);read(k);
for(i=1;i<=m;i++) scanf("%d%d%lld",&X[i],&Y[i],&Z[i]);
for(i=0;i<=2*n*n;i++) fill(f[i]+1,f[i]+n+1,(LL)1e36);
f[0][1]=0;for(i=1;i<=2*n*n;i++){
for(j=1;j<=m;j++) f[i][Y[j]]=min(f[i][Y[j]],f[i-1][X[j]]+Z[j]);
}
if(k<=2*n*n){
for(i=1;i<=n;i++) printf("%d%c",f[k][i]>=1e36?-1:(int)(f[k][i]%mod)," \n"[i==n]);
return;
}
for(i=0;i<=n;i++) for(j=1;j<=n;j++) fill(g[i][j]+1,g[i][j]+n+1,(LL)1e36);
for(i=1;i<=n;i++) g[0][i][i]=0;
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
for(h=1;h<=m;h++) g[i][j][Y[h]]=min(g[i][j][Y[h]],g[i-1][j][X[h]]+Z[h]);
}
}
for(i=0;i<=n*(n+1);i++) fill(dp[i]+1,dp[i]+n+1,(LL)1e36);
for(i=1;i<=n;i++){
pair<LL,int> cir=make_pair((LL)1e30,1);
for(j=1;j<=n;j++) if(g[j][i][i]<1e30&&g[j][i][i]*1.0/j<cir.fi*1.0/cir.se) cir=make_pair(g[j][i][i],j);
if(cir.fi>1e29) continue;
cerr<<i<<' '<<(ll)cir.fi<<' '<<cir.se<<'\n';
for(j=n*n-n;j<=n*n;j++){
int kk=(k-j-n*n)%cir.se;
dp[n*n+kk][i]=min(dp[n*n+kk][i],(k-j-n*n-kk)/cir.se*cir.fi+f[j][i]);
}
}
for(i=n*(n+1);i;i--){
for(j=1;j<=m;j++) dp[i-1][Y[j]]=min(dp[i-1][Y[j]],dp[i][X[j]]+Z[j]);
}
for(i=1;i<=n;i++) printf("%d%c",dp[0][i]>=1e30?-1:(int)(dp[0][i]%mod)," \n"[i==n]);
}
int main(){
int id,t=1;
scanf("%d%d",&id,&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 24ms
memory: 299000kb
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 -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 -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: 0
Wrong Answer
time: 422ms
memory: 1736032kb
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:
-334135544 -199899417 -334145706 -199909579 -334155868 -199919741 -334166030 -199929903 -334176192 -199940065 -334186354 -199950227 -334196516 -199960389 -334206678 -199970551 -334216840 -199980713 -334227002 -199990875 -334237164 -200001037 -334247326 -200011199 -334257488 -200021361 -334267650 -20...
result:
wrong answer 1st numbers differ - expected: '-1', found: '-334135544'
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%