結果

問題 No.1258 コインゲーム
ユーザー eve__fuyukieve__fuyuki
提出日時 2024-01-15 17:07:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 227 ms / 2,000 ms
コード長 1,219 bytes
コンパイル時間 2,722 ms
コンパイル使用メモリ 208,360 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-15 17:08:11
合計ジャッジ時間 14,730 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
6,676 KB
testcase_01 AC 55 ms
6,676 KB
testcase_02 AC 21 ms
6,676 KB
testcase_03 AC 201 ms
6,676 KB
testcase_04 AC 200 ms
6,676 KB
testcase_05 AC 33 ms
6,676 KB
testcase_06 AC 144 ms
6,676 KB
testcase_07 AC 15 ms
6,676 KB
testcase_08 AC 14 ms
6,676 KB
testcase_09 AC 73 ms
6,676 KB
testcase_10 AC 175 ms
6,676 KB
testcase_11 AC 196 ms
6,676 KB
testcase_12 AC 169 ms
6,676 KB
testcase_13 AC 44 ms
6,676 KB
testcase_14 AC 15 ms
6,676 KB
testcase_15 AC 171 ms
6,676 KB
testcase_16 AC 35 ms
6,676 KB
testcase_17 AC 193 ms
6,676 KB
testcase_18 AC 72 ms
6,676 KB
testcase_19 AC 66 ms
6,676 KB
testcase_20 AC 141 ms
6,676 KB
testcase_21 AC 182 ms
6,676 KB
testcase_22 AC 126 ms
6,676 KB
testcase_23 AC 93 ms
6,676 KB
testcase_24 AC 35 ms
6,676 KB
testcase_25 AC 89 ms
6,676 KB
testcase_26 AC 75 ms
6,676 KB
testcase_27 AC 176 ms
6,676 KB
testcase_28 AC 46 ms
6,676 KB
testcase_29 AC 49 ms
6,676 KB
testcase_30 AC 219 ms
6,676 KB
testcase_31 AC 55 ms
6,676 KB
testcase_32 AC 39 ms
6,676 KB
testcase_33 AC 145 ms
6,676 KB
testcase_34 AC 183 ms
6,676 KB
testcase_35 AC 64 ms
6,676 KB
testcase_36 AC 178 ms
6,676 KB
testcase_37 AC 69 ms
6,676 KB
testcase_38 AC 167 ms
6,676 KB
testcase_39 AC 48 ms
6,676 KB
testcase_40 AC 227 ms
6,676 KB
testcase_41 AC 202 ms
6,676 KB
testcase_42 AC 202 ms
6,676 KB
testcase_43 AC 201 ms
6,676 KB
testcase_44 AC 201 ms
6,676 KB
testcase_45 AC 226 ms
6,676 KB
testcase_46 AC 201 ms
6,676 KB
testcase_47 AC 202 ms
6,676 KB
testcase_48 AC 200 ms
6,676 KB
testcase_49 AC 202 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/modint>
using namespace std;
using mint = atcoder::modint1000000007;
void fast_io() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}
int main() {
    fast_io();
    int S;
    cin >> S;
    while (S--) {
        long long n, m, x;
        cin >> n >> m >> x;
        if (n % 2 == 0) {
            if (x == 0) {
                mint ans = (mint(m + 1).pow(n) + mint(m - 1).pow(n)) / 2;
                cout << ans.val() << endl;
            } else {
                mint ans = (mint(m + 1).pow(n) - mint(m - 1).pow(n)) / 2;
                cout << ans.val() << endl;
            }
        } else {
            if (x == 0) {
                mint ans =
                    (mint(m + 1).pow(n - 1) + mint(m - 1).pow(n - 1) +
                     m * (mint(m + 1).pow(n - 1) - mint(m - 1).pow(n - 1))) /
                    2;
                cout << ans.val() << endl;
            } else {
                mint ans =
                    (mint(m + 1).pow(n - 1) - mint(m - 1).pow(n - 1) +
                     m * (mint(m + 1).pow(n - 1) + mint(m - 1).pow(n - 1))) /
                    2;
                cout << ans.val() << endl;
            }
        }
    }
}
0