QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#32484#874. Long Grid CoveringFroggyguaAC ✓6ms3628kbC++1016b2022-05-20 17:01:442022-05-20 17:01:46

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-20 17:01:46]
  • 评测
  • 测评结果:AC
  • 用时:6ms
  • 内存:3628kb
  • [2022-05-20 17:01:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll n;
struct Matrix{
	int g[7][7];
	Matrix(){memset(g,0,sizeof(g));}
	friend Matrix operator * (const Matrix &a,const Matrix &b){
		Matrix c;
		for(int i=1;i<=6;++i){
			for(int j=1;j<=6;++j){
				for(int k=1;k<=6;++k){
					c.g[i][j]=(c.g[i][j]+1LL*a.g[i][k]*b.g[k][j])%mod;
				}
			}
		}
		return c;
	}
}e;
// [ dp[n] dp[n-1] dp[n-2] s[n-1] s[n-2] s[n-3] ]
Matrix mpow(Matrix a,ll b){
	Matrix ans=e;
	while(b){
		if(b&1)ans=ans*a;
		a=a*a;
		b>>=1;
	}
	return ans;
}
void Solve(){
	cin>>n;
	Matrix s;
	s.g[1][2]=s.g[2][3]=1;
	s.g[4][5]=s.g[5][6]=1;
	s.g[1][1]=1;
	s.g[3][1]=1;
	s.g[4][1]=2;
	s.g[5][1]=4;
	s.g[6][1]=2;
	s.g[1][4]=1;
	s.g[6][4]=1;
	Matrix pre;
	pre.g[1][1]=1;
	Matrix ans=pre*mpow(s,n);
	cout<<ans.g[1][1]<<'\n';
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	for(int i=1;i<=6;++i)e.g[i][i]=1;
	int T;
	cin>>T;
	while(T--)Solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 3628kb

input:

4
1
2
3
10

output:

1
3
10
8266

result:

ok 4 number(s): "1 3 10 8266"

Test #2:

score: 0
Accepted
time: 4ms
memory: 3596kb

input:

100
591
417
888
251
792
847
685
3
182
461
102
348
555
956
771
901
712
878
580
631
342
333
285
899
525
725
537
718
929
653
84
788
104
355
624
803
253
853
201
995
536
184
65
205
540
652
549
777
248
405
677
950
431
580
600
846
328
429
134
983
526
103
500
963
400
23
276
704
570
757
410
658
507
620
984
2...

output:

398162564
3923746
347206084
937652677
511984221
356815867
634269583
10
492672877
107350060
647965529
633393631
911425824
746373395
426043114
551287175
772111460
994877654
877599230
88346652
250024200
154039310
461178023
487763582
763918729
537233428
570954868
210301204
911464697
237056565
669291182
...

result:

ok 100 numbers

Test #3:

score: 0
Accepted
time: 6ms
memory: 3580kb

input:

100
955967370573984956
113166936398978672
934415284373637608
774686535590919223
668528836699949629
65629257521619533
811940940990692618
915621972787306932
228144645291423602
690041707309747302
191003462832708740
981404451712468361
900400340973685384
507894895830950112
730342794302458267
292630995901...

output:

544144276
818067446
86599466
313726969
18938569
632700031
797497759
781547720
391588017
878181169
310434443
416689342
69020235
460227545
162825045
321960509
604698726
745824316
617383608
26101176
816251396
489328969
613075753
821553025
821486393
270559043
786443427
729545800
129844182
893901263
9674...

result:

ok 100 numbers

Test #4:

score: 0
Accepted
time: 4ms
memory: 3448kb

input:

100
1000000000000000000
999999999999999999
999999999999999998
999999999999999997
999999999999999996
999999999999999995
999999999999999994
999999999999999993
999999999999999992
999999999999999991
999999999999999990
999999999999999989
999999999999999988
999999999999999987
999999999999999986
9999999999...

output:

776755633
305596516
433884536
271324944
255217955
752347893
279777560
954593517
141741201
121847646
925987319
408911539
615371540
395678394
900921829
709870350
988659472
113218064
830032042
970158982
295607870
455576442
901184396
886355576
365985700
530063682
646456471
944296960
543981115
362793239
...

result:

ok 100 numbers