結果
| 問題 |
No.1879 How many matchings?
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-07-14 17:43:35 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,432 bytes |
| コンパイル時間 | 1,068 ms |
| コンパイル使用メモリ | 112,072 KB |
| 最終ジャッジ日時 | 2025-02-15 10:22:58 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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)%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]*
}
*/
}
}
}