結果
| 問題 |
No.1258 コインゲーム
|
| コンテスト | |
| ユーザー |
msm1993
|
| 提出日時 | 2020-10-23 15:41:40 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 282 ms / 2,000 ms |
| コード長 | 976 bytes |
| コンパイル時間 | 1,697 ms |
| コンパイル使用メモリ | 166,648 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-21 10:09:42 |
| 合計ジャッジ時間 | 14,845 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 50 |
ソースコード
#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;
}
msm1993