QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#669365 | #7308. Permutation and noitatumreP | Afterlife# | AC ✓ | 71ms | 3612kb | C++20 | 2.8kb | 2024-10-23 18:21:46 | 2024-10-23 18:21:48 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
// #define int long long
const int P=1e9+7;
const int mod = 1e9 + 7;
int s;
struct Matrix {
int a[5][5];
Matrix(int _t=0){
for(int i=0;i<s;i++)
for(int j=0;j<s;j++)
a[i][j]=(i==j)*_t;
}
};
Matrix operator *(const Matrix &a,const Matrix &b)
{
Matrix c;
for(int i=0;i<s;i++)
for(int k=0;k<s;k++)
for(int j=0;j<s;j++)
c.a[i][j]=(c.a[i][j]+1ll*a.a[i][k]*b.a[k][j])%P;
return c;
}
Matrix qpow(Matrix a,int b)
{
Matrix ret(1);
while(b)
{
if(b&1)
ret=ret*a;
b>>=1;
a=a*a;
}
return ret;
}
int qpow(int a,int b)
{
int ret=1;
while(b)
{
if(b&1)
ret=1ll*ret*a%P;
b>>=1;
a=1ll*a*a%P;
}
return ret;
}
vector<int> bm(vector<int> s) {
int n = s.size() , L = 0 , m = 0;
vector<int> C(n) , B(n) , T ;
C[0] = B[0] = 1;
int b = 1;
for(int i = 0;i < n;i++) {
++m ;
int d = s[i] % mod;
for(int j = 1;j <= L;j++) d = (d + 1LL * C[j] * s[i - j]) % mod;
if(!d) continue ;
T = C ;
int coef = 1LL * d * qpow(b , mod - 2) % mod;
for(int j = m ; j < n;j++) C[j] = (C[j] - 1LL * coef * B[j - m]%mod + mod) % mod;
if(2 * L > i) continue ;
L = i + 1 - L;
B = T ;
b = d ;
m = 0;
}
C.resize(L + 1) ;
C.erase(C.begin()) ;
for(auto &x : C) x = (mod - x) % mod;
return C ;
}
/// 3*f(n-1) + (-2)*f(n-2) + f(n-3) + (-1)*f(n-4) + 0 * f(n - 5);
/// @return
int f[] = {0,1,2,6,16,36,80,178,394,870,1920,4236,9344};
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
// vector<int> v({1,2,6,16,36,80,178,394,870,1920,4236,9344});
// auto coe = bm(v) ;
// for(auto x : coe) cout << x <<' ' ; cout << '\n';
// const int N = 1e9 ;
// for(int i = 13;i <= N;i++) {
// int p = i % 13 ;
// f[p] = (( (3LL * f[(p + 12) % 13] + (-2LL)*f[(p + 11) % 13] + f[(p + 10) % 13] + (-1LL) * f[(p + 9) % 13]) % mod ) + mod ) % mod;
// if(i == N) {
// cout << f[p] << '\n';
// }
// }
int n;
while(cin>>n)
{
if(n<=12)
cout<<f[n]<<"\n";
else
{
s = 4;
Matrix A, B;
A.a[0][0] = 870, A.a[0][1] = 1920, A.a[0][2] = 4236, A.a[0][3] = 9344;
B.a[0][3] = P - 1;
B.a[1][3] = 1; B.a[1][0] = 1;
B.a[2][3] = P - 2; B.a[2][1] = 1;
B.a[3][3] = 3; B.a[3][2] = 1;
A = A * qpow(B, n - 9);
cout << A.a[0][0] << "\n";
}
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3552kb
input:
4 1000000000
output:
16 861159011
result:
ok 2 number(s): "16 861159011"
Test #2:
score: 0
Accepted
time: 71ms
memory: 3612kb
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