結果

問題 No.1879 How many matchings?
ユーザー gucci0512gucci0512
提出日時 2022-03-18 23:18:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,148 bytes
コンパイル時間 4,257 ms
コンパイル使用メモリ 228,856 KB
実行使用メモリ 51,452 KB
最終ジャッジ日時 2024-04-14 11:31:52
合計ジャッジ時間 6,968 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
51,324 KB
testcase_01 AC 120 ms
51,192 KB
testcase_02 WA -
testcase_03 AC 119 ms
51,228 KB
testcase_04 WA -
testcase_05 AC 123 ms
51,452 KB
testcase_06 WA -
testcase_07 AC 119 ms
51,192 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b) for(int i=b-1;i>=0;i--)
#define rbit(i,a) for(int i=0;i<(1<<a);i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
typedef long long ll;
typedef long double lld;
using namespace std;
using namespace atcoder;
using mint=static_modint<1000000007>;
const ll mod=1e9+7;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const string zton="0123456789";
const string atoz="abcdefghijklmnopqrstuvwxyz";
ll gcd(ll a,ll b){
    ll r;
    r=a%b;
    if(r==0){
        return b;
    }
    else{
        return gcd(b,r);
    }
}
typedef pair<ll,int> P;

ll power2[101010];
ll inv[2001010];
ll kaijou[2001010];
ll kaijou_inv[2001010];
ll nck(ll n,ll k){
    if(n<k)return 0ll;
    else return (((kaijou[n]*kaijou_inv[k])%mod)*kaijou_inv[n-k])%mod;
}
ll npk(ll n,ll k){
    return (kaijou[n]*kaijou_inv[n-k])%mod;
}

typedef vector<int> vec;
typedef vector<vec> mat;

mat mul (mat &A,mat &B){
    mat C(A.size(),vec(B[0].size()));
    rep(i,0,A.size()){
        rep(k,0,B.size()){
            rep(j,0,B[0].size()){
                C[i][j]=(C[i][j]+A[i][k]*B[k][j])%mod;
            }
        }
    }
    return C;
}

mat pow(mat A,ll n){
    mat B(A.size(),vec(A.size()));
    rep(i,0,A.size()){
        B[i][i]=1;
    }
    while(n>0){
        if(n&1)B=mul(B,A);
        A=mul(A,A);
        n>>=1;
    }
    return B;
}

int main(void){
    inv[0]=1;
    inv[1]=1;
    rep(i,2,2001010) inv[i]=inv[mod%i]*(mod-mod/i)%mod;
    kaijou[0]=1ll;
    rep(i,1,2001010){
        kaijou[i]=kaijou[i-1]*1ll*i;
        kaijou[i]%=mod;
    }
    kaijou_inv[0]=1ll;
    rep(i,1,2001010){
        kaijou_inv[i]=kaijou_inv[i-1]*1ll*(inv[i]);
        kaijou_inv[i]%=mod;
    }
    power2[0]=1;
    rep(i,0,101009)power2[i+1]=power2[i]*2%mod;
    int N;cin >> N;
    N/=2;
    N++;
    mat A(2,vec(2));
    A[0][0]=1;
    A[0][1]=1;
    A[1][0]=1;
    A[1][1]=0;
    A=pow(A,N);
    cout << A[1][0] << endl;
}
0