結果

問題 No.541 3 x N グリッド上のサイクルの個数
ユーザー assy1028assy1028
提出日時 2017-07-03 14:24:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 2,595 bytes
コンパイル時間 1,287 ms
コンパイル使用メモリ 117,372 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-15 14:35:49
合計ジャッジ時間 2,990 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 4 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 4 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
testcase_25 AC 4 ms
5,376 KB
testcase_26 AC 4 ms
5,376 KB
testcase_27 AC 4 ms
5,376 KB
testcase_28 AC 4 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 3 ms
5,376 KB
testcase_41 AC 3 ms
5,376 KB
testcase_42 AC 3 ms
5,376 KB
testcase_43 AC 2 ms
5,376 KB
testcase_44 AC 3 ms
5,376 KB
testcase_45 AC 3 ms
5,376 KB
testcase_46 AC 3 ms
5,376 KB
testcase_47 AC 3 ms
5,376 KB
testcase_48 AC 2 ms
5,376 KB
testcase_49 AC 2 ms
5,376 KB
testcase_50 AC 3 ms
5,376 KB
testcase_51 AC 3 ms
5,376 KB
testcase_52 AC 3 ms
5,376 KB
testcase_53 AC 4 ms
5,376 KB
testcase_54 AC 4 ms
5,376 KB
testcase_55 AC 3 ms
5,376 KB
testcase_56 AC 4 ms
5,376 KB
testcase_57 AC 4 ms
5,376 KB
testcase_58 AC 3 ms
5,376 KB
testcase_59 AC 4 ms
5,376 KB
testcase_60 AC 4 ms
5,376 KB
testcase_61 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

ll n;
typedef vector<ll> vec;
typedef vector<vec> mat;

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

mat pow(mat A, ll n) {
    mat B(A.size(), vec(A.size()));
    for (int i = 0; i < A.size(); i++)
        B[i][i] = 1;
    while (n > 0) {
        if (n & 1) B = mult(B, A);
        A = mult(A, A);
        n >>= 1;
    }
    return B;
}

ll solve() {
    mat A(20, vec(20, 0));
    A[0][0] = 1;
    A[1][0] = A[1][1] = A[1][2] = A[1][3] = A[1][8] = 1;
    A[2][0] = A[2][1] = A[2][2] = A[2][3] = A[2][4] = A[2][5] = 1;
    A[3][0] = A[3][1] = A[3][2] = A[3][3] = A[3][4] = A[3][5] = A[3][6] = A[3][7] = 1;
    A[4][0] = A[4][2] = A[4][3] = A[4][4] = A[4][5] = 1;
    A[5][0] = A[5][2] = A[5][3] = A[5][4] = A[5][5] = A[5][6] = 1;
    A[6][0] = A[6][3] = A[6][5] = A[6][6] = A[6][8] = 1;
    A[7][0] = /*A[7][2] =*/ A[7][1] = /*A[7][5] =*/ A[7][6] = A[7][7] = 1;
    A[8][3] = A[8][8] = 1;
    A[9][1] = A[9][2] = A[9][3] = A[9][4] = A[9][5] = A[9][6] = A[9][8] = 1;
    for (int i = 10; i < 20; i++) {
        A[i][i] = A[i][i-10] = 1;
    }
    mat B = pow(A, n+2);
    return B[19][0];
}

void input() {
    cin >> n;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}
0