結果

問題 No.1258 コインゲーム
ユーザー nawawannawawan
提出日時 2020-10-16 22:25:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 197 ms / 2,000 ms
コード長 811 bytes
コンパイル時間 1,295 ms
コンパイル使用メモリ 68,468 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-28 03:48:34
合計ジャッジ時間 10,362 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
4,376 KB
testcase_01 AC 48 ms
4,376 KB
testcase_02 AC 18 ms
4,376 KB
testcase_03 AC 157 ms
4,376 KB
testcase_04 AC 168 ms
4,376 KB
testcase_05 AC 29 ms
4,380 KB
testcase_06 AC 122 ms
4,380 KB
testcase_07 AC 14 ms
4,376 KB
testcase_08 AC 12 ms
4,380 KB
testcase_09 AC 65 ms
4,380 KB
testcase_10 AC 154 ms
4,376 KB
testcase_11 AC 172 ms
4,380 KB
testcase_12 AC 123 ms
4,380 KB
testcase_13 AC 38 ms
4,376 KB
testcase_14 AC 13 ms
4,376 KB
testcase_15 AC 150 ms
4,376 KB
testcase_16 AC 30 ms
4,380 KB
testcase_17 AC 169 ms
4,376 KB
testcase_18 AC 66 ms
4,380 KB
testcase_19 AC 58 ms
4,380 KB
testcase_20 AC 128 ms
4,380 KB
testcase_21 AC 156 ms
4,376 KB
testcase_22 AC 108 ms
4,380 KB
testcase_23 AC 83 ms
4,376 KB
testcase_24 AC 30 ms
4,376 KB
testcase_25 AC 77 ms
4,376 KB
testcase_26 AC 66 ms
4,376 KB
testcase_27 AC 152 ms
4,376 KB
testcase_28 AC 40 ms
4,380 KB
testcase_29 AC 43 ms
4,376 KB
testcase_30 AC 195 ms
4,376 KB
testcase_31 AC 51 ms
4,376 KB
testcase_32 AC 23 ms
4,380 KB
testcase_33 AC 129 ms
4,376 KB
testcase_34 AC 166 ms
4,380 KB
testcase_35 AC 60 ms
4,500 KB
testcase_36 AC 157 ms
4,376 KB
testcase_37 AC 63 ms
4,376 KB
testcase_38 AC 147 ms
4,376 KB
testcase_39 AC 43 ms
4,380 KB
testcase_40 AC 183 ms
4,380 KB
testcase_41 AC 193 ms
4,376 KB
testcase_42 AC 191 ms
4,376 KB
testcase_43 AC 197 ms
4,376 KB
testcase_44 AC 192 ms
4,380 KB
testcase_45 AC 191 ms
4,376 KB
testcase_46 AC 197 ms
4,376 KB
testcase_47 AC 192 ms
4,376 KB
testcase_48 AC 190 ms
4,380 KB
testcase_49 AC 190 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
const int MOD = 1e9 + 7;
long long repow(long long x, long long y){
    if(y == 0) return 1;
    long long res = 1;
    while(y > 0){
        if(y & 1) res = res * x % MOD;
        x = x * x % MOD;
        y >>= 1;
    }
    return res;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int testcase;
    cin >> testcase;
    while(testcase--){
        long long N, M, X;
        cin >> N >> M >> X;
        long long temp = repow(M + 1, N);
        long long temp2 = repow(1 - M, N);
        long long t = repow(2, MOD - 2) % MOD;
        if(X == 1){
            cout << ((temp - temp2) * t % MOD + MOD) % MOD << endl;
        }
        else{
            cout << ((temp + temp2) * t % MOD + MOD) % MOD << endl;
        }
    }
}
0