結果

問題 No.1258 コインゲーム
ユーザー leaf_1415leaf_1415
提出日時 2020-10-16 21:46:57
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 232 ms / 2,000 ms
コード長 643 bytes
コンパイル時間 1,413 ms
コンパイル使用メモリ 51,580 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-28 02:40:07
合計ジャッジ時間 10,649 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
4,380 KB
testcase_01 AC 57 ms
4,376 KB
testcase_02 AC 20 ms
4,380 KB
testcase_03 AC 183 ms
4,376 KB
testcase_04 AC 198 ms
4,376 KB
testcase_05 AC 33 ms
4,376 KB
testcase_06 AC 147 ms
4,380 KB
testcase_07 AC 16 ms
4,376 KB
testcase_08 AC 13 ms
4,376 KB
testcase_09 AC 76 ms
4,376 KB
testcase_10 AC 181 ms
4,376 KB
testcase_11 AC 196 ms
4,376 KB
testcase_12 AC 141 ms
4,376 KB
testcase_13 AC 46 ms
4,376 KB
testcase_14 AC 15 ms
4,376 KB
testcase_15 AC 180 ms
4,380 KB
testcase_16 AC 36 ms
4,376 KB
testcase_17 AC 205 ms
4,380 KB
testcase_18 AC 73 ms
4,380 KB
testcase_19 AC 68 ms
4,380 KB
testcase_20 AC 147 ms
4,376 KB
testcase_21 AC 188 ms
4,376 KB
testcase_22 AC 126 ms
4,380 KB
testcase_23 AC 91 ms
4,380 KB
testcase_24 AC 37 ms
4,376 KB
testcase_25 AC 94 ms
4,380 KB
testcase_26 AC 82 ms
4,376 KB
testcase_27 AC 185 ms
4,376 KB
testcase_28 AC 47 ms
4,376 KB
testcase_29 AC 49 ms
4,380 KB
testcase_30 AC 227 ms
4,376 KB
testcase_31 AC 58 ms
4,380 KB
testcase_32 AC 25 ms
4,380 KB
testcase_33 AC 150 ms
4,376 KB
testcase_34 AC 191 ms
4,380 KB
testcase_35 AC 66 ms
4,380 KB
testcase_36 AC 179 ms
4,380 KB
testcase_37 AC 73 ms
4,376 KB
testcase_38 AC 175 ms
4,376 KB
testcase_39 AC 48 ms
4,376 KB
testcase_40 AC 220 ms
4,376 KB
testcase_41 AC 223 ms
4,380 KB
testcase_42 AC 217 ms
4,380 KB
testcase_43 AC 219 ms
4,380 KB
testcase_44 AC 225 ms
4,380 KB
testcase_45 AC 223 ms
4,380 KB
testcase_46 AC 232 ms
4,380 KB
testcase_47 AC 229 ms
4,376 KB
testcase_48 AC 229 ms
4,380 KB
testcase_49 AC 215 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#define llint long long
#define mod 1000000007

using namespace std;

llint T;
llint n, m, x;
llint inv2;

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

int main(void)
{
  ios::sync_with_stdio(0);
  cin.tie(0);

  inv2 = (mod+1)/2;

  cin >> T;
  for(int t = 0; t < T; t++){
    cin >> n >> m >> x;

    llint ans;
    llint a = modpow(1+m, n), b = modpow(1+mod-m, n);
    if(x == 0) ans = (a + b) * inv2 % mod;
    else ans = (a + mod - b) * inv2 % mod;
    cout << ans << endl;
  }
  return 0;
}
0