結果

問題 No.1258 コインゲーム
ユーザー eve__fuyuki
提出日時 2024-01-15 17:07:56
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 264 ms / 2,000 ms
コード長 1,219 bytes
コンパイル時間 2,572 ms
コンパイル使用メモリ 199,012 KB
最終ジャッジ日時 2025-02-18 20:12:24
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

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