結果
問題 |
No.1879 How many matchings?
|
ユーザー |
|
提出日時 | 2023-07-14 17:13:22 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,494 bytes |
コンパイル時間 | 1,048 ms |
コンパイル使用メモリ | 112,824 KB |
最終ジャッジ日時 | 2025-02-15 10:21:54 |
ジャッジサーバーID (参考情報) |
judge4 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 7 WA * 8 |
ソースコード
#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; } 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; auto An = multi_matrix(A,n-1,2); if(N==2){ cout<<1<<endl; }else{ //2 ll ans= (An[0][0]*1+An[0][1]*1)%MOD; cout<<ans<<endl; } } }