結果

問題 No.1258 コインゲーム
ユーザー SSRSSSRS
提出日時 2020-10-16 21:35:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 257 ms / 2,000 ms
コード長 732 bytes
コンパイル時間 1,737 ms
コンパイル使用メモリ 166,284 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-28 02:38:12
合計ジャッジ時間 11,418 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
4,380 KB
testcase_01 AC 62 ms
4,380 KB
testcase_02 AC 23 ms
4,376 KB
testcase_03 AC 194 ms
4,380 KB
testcase_04 AC 221 ms
4,376 KB
testcase_05 AC 36 ms
4,376 KB
testcase_06 AC 163 ms
4,376 KB
testcase_07 AC 17 ms
4,380 KB
testcase_08 AC 15 ms
4,376 KB
testcase_09 AC 80 ms
4,376 KB
testcase_10 AC 197 ms
4,380 KB
testcase_11 AC 214 ms
4,376 KB
testcase_12 AC 156 ms
4,376 KB
testcase_13 AC 48 ms
4,380 KB
testcase_14 AC 17 ms
4,380 KB
testcase_15 AC 189 ms
4,376 KB
testcase_16 AC 39 ms
4,380 KB
testcase_17 AC 212 ms
4,380 KB
testcase_18 AC 81 ms
4,376 KB
testcase_19 AC 73 ms
4,380 KB
testcase_20 AC 159 ms
4,380 KB
testcase_21 AC 198 ms
4,380 KB
testcase_22 AC 137 ms
4,380 KB
testcase_23 AC 105 ms
4,380 KB
testcase_24 AC 38 ms
4,380 KB
testcase_25 AC 97 ms
4,376 KB
testcase_26 AC 82 ms
4,380 KB
testcase_27 AC 193 ms
4,376 KB
testcase_28 AC 51 ms
4,376 KB
testcase_29 AC 57 ms
4,376 KB
testcase_30 AC 240 ms
4,380 KB
testcase_31 AC 61 ms
4,380 KB
testcase_32 AC 28 ms
4,376 KB
testcase_33 AC 166 ms
4,380 KB
testcase_34 AC 203 ms
4,380 KB
testcase_35 AC 71 ms
4,380 KB
testcase_36 AC 205 ms
4,376 KB
testcase_37 AC 76 ms
4,380 KB
testcase_38 AC 184 ms
4,380 KB
testcase_39 AC 54 ms
4,380 KB
testcase_40 AC 251 ms
4,380 KB
testcase_41 AC 244 ms
4,380 KB
testcase_42 AC 238 ms
4,380 KB
testcase_43 AC 250 ms
4,376 KB
testcase_44 AC 245 ms
4,380 KB
testcase_45 AC 249 ms
4,376 KB
testcase_46 AC 243 ms
4,376 KB
testcase_47 AC 247 ms
4,380 KB
testcase_48 AC 246 ms
4,380 KB
testcase_49 AC 257 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long modsub(long long a, long long b){
	return (a % MOD - b % MOD + MOD) % MOD;
}
long long modpow(long long a, long long b){
	long long ans = 1;
	while (b > 0){
		if (b % 2 == 1){
			ans *= a;
			ans %= MOD;
		}
		a *= a;
		a %= MOD;
		b /= 2;
	}
	return ans;
}
long long modinv(long long a){
	return modpow(a, MOD - 2);
}
int main(){
  int S;
  cin >> S;
  for (int i = 0; i < S; i++){
    int N, M, X;
    cin >> N >> M >> X;
    if (X == 0){
      cout << (modpow(1 + M, N) + modpow(modsub(1, M), N)) * modinv(2) % MOD << endl;
    } else {
      cout << modsub(modpow(1 + M, N), modpow(modsub(1, M), N)) * modinv(2) % MOD << endl;
    }
  }
}
0