結果

問題 No.1258 コインゲーム
ユーザー tnakao0123
提出日時 2020-10-17 22:43:10
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 1,320 bytes
コンパイル時間 768 ms
コンパイル使用メモリ 94,952 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-21 03:12:55
合計ジャッジ時間 6,801 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

/* -*- coding: utf-8 -*-
*
* 1258.cc: No.1258 - 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 */
const int MOD = 1000000007;
/* typedef */
typedef long long ll;
struct Mat2 {
int a, b, c, d;
Mat2() {}
Mat2(int _a, int _b, int _c, int _d):
a(_a), b(_b), c(_c), d(_d) {}
Mat2 operator*(const Mat2 &m) const {
return Mat2(((ll)a * m.a % MOD + (ll)b * m.c % MOD) % MOD,
((ll)a * m.b % MOD + (ll)b * m.d % MOD) % MOD,
((ll)c * m.a % MOD + (ll)d * m.c % MOD) % MOD,
((ll)c * m.b % MOD + (ll)d * m.d % MOD) % MOD);
}
Mat2 operator^(int n) {
Mat2 p(1, 0, 0, 1), a = *this;
while (n > 0) {
if (n & 1) p = p * a;
a = a * a;
n >>= 1;
}
return p;
}
};
/* global variables */
/* subroutines */
/* main */
int main() {
int tn;
scanf("%d", &tn);
while (tn--) {
int n, m, x;
scanf("%d%d%d", &n, &m, &x);
Mat2 ma(1, m, m, 1);
Mat2 mb = ma ^ n;
printf("%d\n", (x == 0) ? mb.a : mb.c);
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0