結果

問題 No.1879 How many matchings?
ユーザー serufe_niserufe_ni
提出日時 2022-03-22 20:16:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,146 bytes
コンパイル時間 1,501 ms
コンパイル使用メモリ 163,128 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-18 20:44:57
合計ジャッジ時間 2,206 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
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>
using namespace std;
#define int long long 
const int mod = 1000000007;
int n;
int martxB[2][2] = {1, 1, 1, 0};
int martxA[2] = {1, 1};
int ans[2];
void multiply(int x[][2], int y[][2]) {
    int res[2][2];
    memset(res, 0, sizeof res);
    for (int i = 0; i < 2; i ++) {
        for (int j = 0; j < 2; j ++) {
            for (int k = 0; k < 2; k ++) {
                res[i][j] = (x[i][k] * y[k][j] + res[i][j]) % mod;
            }
        }
    }
    memcpy(x,res,sizeof res);
}
void Qpow(int x[][2], int k) {
    int res[2][2];
    memset(res, 0, sizeof res);
    for (int i = 0; i < 2; i ++) {
        res[i][i] = 1;
    }
    while (k) {
        if (k % 2) {
            multiply(res, x);
        }
        multiply(x, x);
        k /= 2;
    }
    memcpy(x, res, sizeof res);
}
signed main () {
    cin >> n;
    if (n <= 2) {
        cout << 1;
        return 0;
    }
    Qpow(martxB, n / 2 - 1);
    for (int i = 0; i < 2; i ++) {
        for (int k =0; k < 2; k ++) {
            ans[i] = (ans[i] + martxB[i][k] * martxA[k] % mod ) % mod;
        }
    }
    cout << 2 * ans[0] * (n % 2 ? n:1) << endl;
}   
0