QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#835473#7308. Permutation and noitatumrePAuroreAC ✓58ms3600kbC++231.3kb2024-12-28 12:02:442024-12-28 12:02:45

Judging History

This is the latest submission verdict.

  • [2024-12-28 12:02:45]
  • Judged
  • Verdict: AC
  • Time: 58ms
  • Memory: 3600kb
  • [2024-12-28 12:02:44]
  • Submitted

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int buf[105];
inline void print(int x,char ch=' '){
	if(x<0) putchar('-'),x=-x;
	int tot=0;
	do{
		buf[++tot]=x%10;
		x/=10;
	}while(x);
	for(int i=tot;i;i--) putchar(buf[i]+'0');
	putchar(ch);
}
const int MAXN=4,mod=1e9+7;
struct matrix{
	int m[MAXN][MAXN];
	matrix(){
		memset(m,0,sizeof(m));
	}
	int *operator[](const int &x){
		return m[x];
	}
	matrix friend operator*(matrix a,matrix b){
		matrix c;
		for(int i=0;i<MAXN;i++)
			for(int k=0;k<MAXN;k++)
				for(int j=0;j<MAXN;j++) c[i][j]=(c[i][j]+a[i][k]*b[k][j])%mod;
		return c;
	}
};
int n;
matrix qpow(matrix a,int b){
	matrix ans=matrix(),base=a;
	for(int i=0;i<MAXN;i++) ans[i][i]=1;
	while(b){
		if(b&1) ans=ans*base;
		base=base*base;
		b>>=1;
	}
	return ans;
}
signed main(){
	while(cin>>n){
		if(n==1) print(1,'\n');
		else if(n==2) print(2,'\n');
		else if(n==3) print(6,'\n');
		else{
			matrix f,g;
			f[0][0]=16,f[0][1]=6,f[0][2]=2,f[0][3]=2;
			
			g[0][0]=2,g[2][0]=1,g[3][0]=1;
			g[0][1]=1;
			g[1][2]=1;
			g[3][3]=1;
			
			f=f*qpow(g,n-4);
			print(f[0][0],'\n');
		}
	}
	return 0;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3600kb

input:

4
1000000000

output:

16
861159011

result:

ok 2 number(s): "16 861159011"

Test #2:

score: 0
Accepted
time: 58ms
memory: 3536kb

input:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
...

output:

1
2
6
16
36
80
178
394
870
1920
4236
9344
20610
45458
100262
221136
487732
1075728
2372594
5232922
11541574
25455744
56144412
123830400
273116546
602377506
328585407
930287362
462952218
254489838
439267033
341486279
937462398
314191817
969869915
877202216
68596237
107062384
91326979
251250197
609562...

result:

ok 20000 numbers

Extra Test:

score: 0
Extra Test Passed