結果

問題 No.1073 無限すごろく
ユーザー Y17Y17
提出日時 2020-06-05 22:46:20
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,467 bytes
コンパイル時間 1,767 ms
コンパイル使用メモリ 172,492 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-22 16:39:05
合計ジャッジ時間 2,985 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,384 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define MOD 1000000007

int pow_mod(int n, int m){
	int ans = 1;
	while(m > 0){
		if(m & 1) ans = (ans * n) % MOD;
		n = (n * n) % MOD;
		m >>= 1;
	}
	return ans;
}

typedef vector<int> vec;
typedef vector<vec> mat;

mat mul(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(mat a, int 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 = mul(b, a);
		a = mul(a, a);
		n >>= 1;
	}
	return b;
}

signed main(){
	int n;
	cin >> n;

	int v[7] = {};
	v[0] = 1;
	for(int i = 1;i <= 6;i++){
		for(int j = 0;j < i;j++){
			v[i] += v[j]*pow_mod(6, MOD-2) % MOD;
			v[i] %= MOD;
		}
	}

	int ydk = pow_mod(6, MOD-2);

	mat a(6, vec(6));
	a[0][0] = a[0][1] = a[0][2] = a[0][3] = a[0][4] = a[0][5] = ydk;
	a[1][0] = a[2][1] = a[3][2] = a[4][3] = a[5][4] = 1;


	auto b = pow_mat(a, n); 

	if(n < 7){
		cout << v[n] << endl;
	}else{
		int ans = 0;
		for(int i = 0;i < 6;i++){
			ans = (ans + b[5][i]*v[6-i-1]%MOD)%MOD;
		}
		cout << ans << endl;
	}

	return 0;
}
0