結果

問題 No.1258 コインゲーム
ユーザー 👑 NachiaNachia
提出日時 2020-10-17 21:49:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 277 ms / 2,000 ms
コード長 976 bytes
コンパイル時間 1,380 ms
コンパイル使用メモリ 164,648 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-28 08:40:40
合計ジャッジ時間 12,875 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
4,376 KB
testcase_01 AC 66 ms
4,380 KB
testcase_02 AC 25 ms
4,376 KB
testcase_03 AC 216 ms
4,376 KB
testcase_04 AC 246 ms
4,380 KB
testcase_05 AC 41 ms
4,380 KB
testcase_06 AC 176 ms
4,376 KB
testcase_07 AC 19 ms
4,380 KB
testcase_08 AC 16 ms
4,380 KB
testcase_09 AC 92 ms
4,380 KB
testcase_10 AC 216 ms
4,380 KB
testcase_11 AC 239 ms
4,380 KB
testcase_12 AC 176 ms
4,380 KB
testcase_13 AC 54 ms
4,376 KB
testcase_14 AC 19 ms
4,380 KB
testcase_15 AC 209 ms
4,380 KB
testcase_16 AC 42 ms
4,376 KB
testcase_17 AC 240 ms
4,376 KB
testcase_18 AC 88 ms
4,380 KB
testcase_19 AC 82 ms
4,380 KB
testcase_20 AC 174 ms
4,376 KB
testcase_21 AC 224 ms
4,376 KB
testcase_22 AC 155 ms
4,376 KB
testcase_23 AC 115 ms
4,380 KB
testcase_24 AC 43 ms
4,376 KB
testcase_25 AC 109 ms
4,376 KB
testcase_26 AC 93 ms
4,380 KB
testcase_27 AC 218 ms
4,380 KB
testcase_28 AC 58 ms
4,380 KB
testcase_29 AC 62 ms
4,380 KB
testcase_30 AC 277 ms
4,380 KB
testcase_31 AC 70 ms
4,376 KB
testcase_32 AC 30 ms
4,376 KB
testcase_33 AC 187 ms
4,376 KB
testcase_34 AC 227 ms
4,380 KB
testcase_35 AC 78 ms
4,376 KB
testcase_36 AC 222 ms
4,380 KB
testcase_37 AC 87 ms
4,380 KB
testcase_38 AC 207 ms
4,380 KB
testcase_39 AC 60 ms
4,376 KB
testcase_40 AC 276 ms
4,380 KB
testcase_41 AC 273 ms
4,380 KB
testcase_42 AC 274 ms
4,380 KB
testcase_43 AC 271 ms
4,376 KB
testcase_44 AC 272 ms
4,380 KB
testcase_45 AC 272 ms
4,380 KB
testcase_46 AC 272 ms
4,380 KB
testcase_47 AC 275 ms
4,380 KB
testcase_48 AC 274 ms
4,380 KB
testcase_49 AC 276 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

const ULL M = 1000000007;

const int matrix_sz = 2;

struct Matrix {
	ULL A[matrix_sz][matrix_sz] = {};
	ULL* operator[](int x) { return A[x]; }
	const ULL* operator[](int x) const { return A[x]; }
};

Matrix MatrixId() {
	Matrix ans;
	rep(i, matrix_sz) ans[i][i] = 1;
	return ans;
}
Matrix operator*(Matrix a, Matrix b) {
	Matrix ans;
	rep(i, matrix_sz) rep(j, matrix_sz) rep(k, matrix_sz)
		ans[i][j] = (ans[i][j] + a[i][k] * b[k][j]) % M;
	return ans;
}
Matrix operator^(Matrix a, ULL i) {
	if (i == 0) return MatrixId();
	Matrix ans = (a * a) ^ (i / 2);
	if (i & 1) ans = ans * a;
	return ans;
}


int main() {
	int S; scanf("%d", &S);
	while (S--) {
		ULL N, g, x; scanf("%llu%llu%llu", &N, &g, &x);
		Matrix G;
		G[0][0] = 1;
		G[1][1] = 1;
		G[0][1] = g;
		G[1][0] = g;
		G = G ^ N;
		cout << G[0][x] << endl;
	}

	return 0;
}
0