結果
| 問題 |
No.569 3 x N グリッドのパスの数
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2017-09-21 19:53:25 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 2,158 bytes |
| コンパイル時間 | 906 ms |
| コンパイル使用メモリ | 83,904 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-08 19:33:17 |
| 合計ジャッジ時間 | 2,487 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 60 |
ソースコード
/* -*- coding: utf-8 -*-
*
* 569.cc: No.569 3 x N グリッドのパスの数 - yukicoder
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
typedef long long ll;
const ll MOD = 1000000007;
// pattern:
// 0: 1000, 1: 0100, 2: 0010, 3: 0001,
// 4: 1220, 5: 1202, 6: 1022,
// 7: 0122,
// 8: 2210,
// 9: 2201, 10: 2021, 11: 0221
const int N = 12;
typedef ll mat[N][N];
const mat IM = {
{ 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 },
{ 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0 },
{ 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0 },
{ 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1 },
{ 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 },
{ 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0 },
{ 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1 },
{ 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 },
};
/* typedef */
typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;
/* global variables */
/* subroutines */
void mulmat(const mat a, const mat b, mat c) { // a * b => c
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++) {
c[i][j] = 0;
for (int k = 0; k < N; k++) {
c[i][j] += a[i][k] * b[k][j];
c[i][j] %= MOD;
}
}
}
inline void initmat(mat a) {
for (int i = 0; i < N; i++) {
fill(a[i], a[i] + N, 0);
a[i][i] = 1;
}
}
inline void copymat(const mat a, mat b) { // a -> b
memcpy(b, a, sizeof(mat));
}
void powmat(const mat a, ll b, mat p) { // a^b => c
mat aa, c;
initmat(p);
copymat(a, aa);
while (b > 0LL) {
if ((b & 1LL) != 0LL) {
mulmat(p, aa, c);
copymat(c, p);
}
mulmat(aa, aa, c);
copymat(c, aa);
b >>= 1;
}
}
/* main */
int main() {
ll n;
cin >> n;
mat p;
powmat(IM, n + 1, p);
printf("%lld\n", p[3][0]);
return 0;
}
tnakao0123