結果

問題 No.1879 How many matchings?
ユーザー HIcoderHIcoder
提出日時 2023-07-14 17:43:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,432 bytes
コンパイル時間 1,047 ms
コンパイル使用メモリ 114,624 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-14 07:30:37
合計ジャッジ時間 1,892 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,356 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,352 KB
testcase_06 WA -
testcase_07 AC 2 ms
4,348 KB
testcase_08 WA -
testcase_09 AC 1 ms
4,352 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
4,372 KB
testcase_14 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<set> 
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
#include <unordered_set>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<ll,ll> P;
typedef pair<int,P> PP;
const ll MOD=1e9+7;


vector<vector<ll> > mat(vector<vector<ll> > A,vector<vector<ll> > B,int N){
    //A*B
    vector<vector<ll> > C(N,vector<ll>(N));
    
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            ll ans=0;
            for(int k=0;k<N;k++){
                ans = (ans + A[i][k]*B[k][j]%MOD)%MOD;
            }
            C[i][j] = ans;
        }
    }
    return C;

}


//行列xのy乗
vector<vector<ll>> multi_matrix(vector<vector<ll>> x, ll y ,int N){

    vector<vector<ll> > pow(N,vector<ll>(N));
    for(int i=0;i<N;i++) pow[i][i]=1;//単位行列
    
    while(y>0){
        if(y&1){
            pow = mat(pow,x,N);
        }
        y = y>>1;
        x = mat(x,x,N);
    }

    return pow;
} 

int main(){
    ll N;
    cin>>N;
    if(N%2==1){
        //最大マッチングが0の1とおり
        cout<<1<<endl;
    }else{

        vector<vector<ll>> A(2,vector<ll>(2,0));
        A[0][0]=1,A[0][1]=1;
        A[1][0]=1,A[1][1]=0;

        ll n=N/2;
        
        if(N==2){
            cout<<1<<endl;
        }else if(N==4){
            cout<<2<<endl;
        }
        else
        {
            ll ans=0;

            
            auto An = multi_matrix(A,n-2,2);
            /*
            cout<<"An[0][0]="<<An[0][0]<<endl;
            cout<<"An[0][1]="<<An[0][1]<<endl;
            cout<<"An[1][0]="<<An[1][0]<<endl;
            cout<<"An[1][1]="<<An[1][1]<<endl;
            */

            ans+=An[0][0]*2%MOD;
                ans%=MOD;

                ans+=An[0][1];
                ans%=MOD;


            /*
            if(n%2==0){
                ans+=An[0][0]*2%MOD;
                ans%=MOD;

                ans+=An[0][1];
                ans%=MOD;


            }else{
                ans+=An[1][0]*2;
                ans%=MOD;

            }
            */

            cout<<ans<<endl;




            /*

            if(n%2==1){
                ans+=An[0][0]*2%MOD;
                ans%=MOD;

                ans+=An[0][1];
                ans%=MOD;

                

            }else{

                An[1][0]*

            }
            */

        }

    }
}
0