QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#269404#7775. 【模板】矩阵快速幂275307894a10 715ms1736740kbC++142.2kb2023-11-29 16:30:502023-11-29 16:30:51

Judging History

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

  • [2023-11-29 16:30:51]
  • 评测
  • 测评结果:10
  • 用时:715ms
  • 内存:1736740kb
  • [2023-11-29 16:30:50]
  • 提交

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)1e38); 
	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;//cerr<<kk<<'\n';
			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]>1e36?-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: 10
Accepted

Test #1:

score: 10
Accepted
time: 24ms
memory: 299188kb

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:

395495792 395495781 395495783 395495839 395495793 395495789 395495754 395495832 395495845 395495755 395495823 395495773 395495753 395495800 395495782 395495763 395495847 395495761 395495794 395495791 395495786 395495821 395495798 395495765 395495772 395495770 395495757 395495819 395495843 395495828 ...

result:

ok 100 numbers

Test #2:

score: 0
Accepted
time: 35ms
memory: 299560kb

input:

1
1
100 200 998858598565699977
89 61 596014036562538539
89 84 921297646113897322
61 84 946923234442637386
61 35 641628261157284465
84 35 979893473772327497
84 78 700172488379560611
35 78 963617193748189613
35 54 951598888254521423
78 54 680825215292116806
78 21 737055858973038555
54 21 7491794406112...

output:

590375247 265938345 203065828 597548045 369717762 226160283 377877020 360218254 956162456 408060901 387231165 759578975 67601808 790211315 608425007 343195480 177353482 436533546 717630459 417099733 542227025 861764246 913806375 587268602 989846681 435016550 66609901 817090566 256847656 844441854 94...

result:

ok 100 numbers

Test #3:

score: 0
Accepted
time: 31ms
memory: 299512kb

input:

1
1
100 181 348568663892999968
25 19 990622898175774733
19 94 871060999389241529
94 24 969317630558501400
24 43 908457844888427461
43 52 816088481082287266
52 62 978618931332609685
62 99 761714433396732044
99 85 741344935503895668
85 64 964684335126604843
64 69 988098065125373655
69 31 7506975506815...

output:

916998469 916998469 916998469 76035207 62461893 916998469 389136594 916998469 916998469 173423529 164423356 822964468 626456020 916998469 744111524 916998469 398953850 916998469 342238577 916998469 255074799 784015663 916998469 740933556 587088671 811719512 916998469 916998469 916998469 916998469 14...

result:

ok 100 numbers

Test #4:

score: 0
Accepted
time: 20ms
memory: 296520kb

input:

1
1
100 189 295064635124730243
18 50 754672892083203214
50 88 962632394366987404
88 15 906700334097319336
15 26 967741400981618572
26 91 996214498763867892
91 35 882157548994344280
35 68 983621159612138407
68 51 563935036482744182
51 75 991205513962219551
75 72 974025375183814852
72 11 7979447663592...

output:

663199381 739882534 663199381 28600701 663199381 944601671 836329160 894091561 629507606 663199381 246830507 663199381 491987421 663199381 802123884 663199381 663199381 663199381 414785533 989396289 663199381 663199381 663199381 663199381 663199381 663199381 663199381 663199381 663199381 663199381 4...

result:

ok 100 numbers

Test #5:

score: 0
Accepted
time: 11ms
memory: 91532kb

input:

1
254
40 74 997173688939799978
38 6 890721839505665075
6 10 992308491267087930
10 29 960202932780090595
29 20 952827125924298715
20 34 868314670055961466
34 31 756448635709788087
31 14 857625921909632516
14 18 917667459973696862
18 21 985939328882662624
21 1 734882468602343649
1 11 66102593854575036...

output:

177014577 177014577 177014577 885341552 472856470 177014577 363547548 177014577 499847464 653076748 177014577 177014577 177014577 177014577 487939796 177014577 213466543 586729345 244952763 177014577 177014577 177014577 177014577 890105934 177014577 177014577 890105934 177014577 177014577 798890006 ...

result:

ok 3575 numbers

Test #6:

score: 0
Accepted
time: 12ms
memory: 70852kb

input:

1
356
32 47 967844399484634837
4 30 776954643355911997
30 20 811634053140142741
20 22 747630229183579429
22 2 806282875388761050
2 26 719793351534499411
26 17 797537828929335673
17 24 890423236992687627
24 21 970792227007588899
21 8 850078803097295262
8 15 958474507028658347
15 1 972636122087215360
...

output:

890097469 525779071 636798453 776362497 776362497 687961593 158033324 776362497 345910504 380622623 239804834 440670451 137231885 985041116 222869127 137231885 705696901 637534644 347889826 696528073 291555427 146553026 776362497 624486185 137231885 642408114 520519927 137231885 438373632 263924254 ...

result:

ok 4784 numbers

Subtask #2:

score: 0
Wrong Answer

Test #7:

score: 0
Wrong Answer
time: 525ms
memory: 1735532kb

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
Wrong Answer

Dependency #1:

100%
Accepted

Test #19:

score: 0
Wrong Answer
time: 35ms
memory: 298732kb

input:

4
1
100 101 6888995999928874698772868926699656683388498575797893294688976887
25 90 495511874996847106
90 84 495511874996847106
84 82 495511874996847106
82 40 495511874996847106
40 97 495511874996847106
97 5 495511874996847106
5 24 495511874996847106
24 16 495511874996847106
16 19 495511874996847106
...

output:

-242181964 -242181971 -242181914 -242181955 -242181926 -242181981 -242181950 -242181900 -242181972 -242181962 -242181933 -242181903 -242181974 -242181957 -242181910 -242181924 -242181939 -242181952 -242181923 -242181951 -242181963 -242181922 -242181986 -242181925 -242181932 -242181997 -242181992 -24...

result:

wrong answer 1st numbers differ - expected: '662900138', found: '-242181964'

Subtask #5:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #25:

score: 15
Accepted
time: 498ms
memory: 1736004kb

input:

5
1
300 301 969767789936486493
164 284 964646444984408140
284 241 964646444984408140
241 281 964646444984408140
281 138 964646444984408140
138 242 964646444984408140
242 112 964646444984408140
112 217 964646444984408140
217 170 964646444984408140
170 31 964646444984408140
31 300 964646444984408140
3...

output:

562333388 562333371 562333450 562333457 562333181 562333366 562333433 562333276 562333204 562333354 562333361 562333374 562333436 562333405 562333369 562333286 562333360 562333318 562333396 562333251 562333480 562333220 562333333 562333460 562333359 562333295 562333293 562333335 562333402 562333226 ...

result:

ok 300 numbers

Test #26:

score: 0
Accepted
time: 715ms
memory: 1735480kb

input:

5
1
300 600 798876399989994933
7 196 978372754397099680
7 150 850366341978113658
196 150 741178931696536015
196 241 918555502737513857
150 241 755464499814711391
150 249 715712249601810459
241 249 834572033520725671
241 172 840925258261612828
249 172 765221764158211117
249 92 987381804975984305
172 ...

output:

103349950 4999241 142118823 400506111 885559364 196293932 888044807 431387396 656847997 382995767 154772964 775074870 360166602 822043040 871256466 771891985 42704853 943406678 158027440 486796258 972364206 191106105 158852164 825942858 973808447 981369554 98907807 66904970 935447293 466970182 66575...

result:

ok 300 numbers

Test #27:

score: 0
Accepted
time: 487ms
memory: 1733056kb

input:

5
1
300 319 999568963877948597
127 165 930758488326418731
165 155 912956207532166981
155 28 930375923771407137
28 174 952825751389557214
174 170 969510032281804566
170 241 896480622553779223
241 54 857133548480482773
54 22 748966877674282581
22 105 992399083086354199
105 73 833098032662288489
73 199...

output:

615687095 22340881 220606255 926757569 403722771 339583612 218798352 675170360 910785402 527927433 468935392 80089701 112798914 308829476 977528530 484462850 559184887 21739752 111487269 309000604 260902067 244633941 296132705 230226837 668779298 283618195 103042591 779688636 992598043 560518243 807...

result:

ok 300 numbers

Test #28:

score: 0
Accepted
time: 623ms
memory: 1736740kb

input:

5
1
300 548 824591615686303801
277 294 884790950503796190
294 241 928062180696957669
241 164 997854303092696029
164 296 922799499949016142
296 248 944988731600431360
248 153 831789824022472151
153 180 666918059700566083
180 87 790575536963511661
87 285 804674576894023412
285 211 822686794867787872
2...

output:

278188366 278188366 278188366 278188366 278188366 50768692 278188366 278188366 278188366 278188366 888601612 278188366 371280094 739457050 790269377 850776214 278188366 278188366 278188366 18157734 278188366 278188366 278188366 811551034 356306457 730311889 608326520 278188366 109322194 278188366 27...

result:

ok 300 numbers

Test #29:

score: 0
Accepted
time: 711ms
memory: 392204kb

input:

5
40
120 131 679889999068592637
118 98 812545734198160781
98 91 917010970269512244
91 95 698053144863731543
95 14 628901820405095492
14 22 889645699347522207
22 51 871704747332576532
51 19 994723476638446914
19 108 935669854949015658
108 83 944628276409310798
83 6 997623504444369992
6 44 89978656209...

output:

347797689 625661551 663318864 430007740 779572483 678295713 604524795 482364258 563274534 733628768 109065455 813167359 237637495 314851932 792047890 731351621 209595139 105858678 353663190 171125513 429932280 382442950 478291233 424842463 792632068 72912215 20364781 716856724 782743587 623493496 35...

result:

ok 3150 numbers

Test #30:

score: -15
Wrong Answer
time: 474ms
memory: 280808kb

input:

5
5333
96 163 896598775993796678
48 22 988628974528111232
22 79 974327267551042014
79 89 963371577075408650
89 35 977281141965145271
35 83 933480640131723472
83 71 671664664777649600
71 6 618937617718672760
6 18 899457718948743597
18 34 950491723718783148
34 50 977014890463222654
50 25 6638914519516...

output:

301347522 422213537 486604400 730721865 21694591 422213537 422213537 254465456 422213537 422213537 611991526 115365870 422213537 422213537 422213537 422213537 868835950 422213537 422213537 422213537 422213537 422213537 422213537 212714492 422213537 966025026 459165854 321559202 422213537 422213537 2...

result:

wrong answer 21140th numbers differ - expected: '-1', found: '948764661'

Subtask #6:

score: 0
Skipped

Dependency #3:

0%