結果

問題 No.1258 コインゲーム
ユーザー w2w2w2w2
提出日時 2020-10-16 22:01:04
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 2,759 bytes
コンパイル時間 1,773 ms
コンパイル使用メモリ 199,320 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-28 03:05:19
合計ジャッジ時間 7,350 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
4,376 KB
testcase_01 AC 20 ms
4,380 KB
testcase_02 AC 8 ms
4,376 KB
testcase_03 AC 66 ms
4,380 KB
testcase_04 AC 75 ms
4,376 KB
testcase_05 AC 13 ms
4,376 KB
testcase_06 AC 56 ms
4,376 KB
testcase_07 AC 7 ms
4,380 KB
testcase_08 AC 6 ms
4,376 KB
testcase_09 AC 28 ms
4,376 KB
testcase_10 AC 64 ms
4,376 KB
testcase_11 AC 72 ms
4,376 KB
testcase_12 AC 53 ms
4,380 KB
testcase_13 AC 17 ms
4,376 KB
testcase_14 AC 6 ms
4,380 KB
testcase_15 AC 65 ms
4,376 KB
testcase_16 AC 13 ms
4,376 KB
testcase_17 AC 70 ms
4,376 KB
testcase_18 AC 26 ms
4,376 KB
testcase_19 AC 24 ms
4,376 KB
testcase_20 AC 55 ms
4,380 KB
testcase_21 AC 72 ms
4,380 KB
testcase_22 AC 49 ms
4,376 KB
testcase_23 AC 36 ms
4,376 KB
testcase_24 AC 14 ms
4,376 KB
testcase_25 AC 33 ms
4,380 KB
testcase_26 AC 29 ms
4,376 KB
testcase_27 AC 65 ms
4,376 KB
testcase_28 AC 18 ms
4,380 KB
testcase_29 AC 18 ms
4,376 KB
testcase_30 AC 82 ms
4,376 KB
testcase_31 AC 21 ms
4,380 KB
testcase_32 AC 10 ms
4,376 KB
testcase_33 AC 53 ms
4,376 KB
testcase_34 AC 70 ms
4,376 KB
testcase_35 AC 26 ms
4,376 KB
testcase_36 AC 69 ms
4,380 KB
testcase_37 AC 28 ms
4,376 KB
testcase_38 AC 63 ms
4,376 KB
testcase_39 AC 18 ms
4,376 KB
testcase_40 AC 86 ms
4,380 KB
testcase_41 AC 86 ms
4,376 KB
testcase_42 AC 86 ms
4,380 KB
testcase_43 AC 86 ms
4,376 KB
testcase_44 AC 89 ms
4,376 KB
testcase_45 AC 89 ms
4,380 KB
testcase_46 AC 86 ms
4,376 KB
testcase_47 AC 88 ms
4,380 KB
testcase_48 AC 84 ms
4,376 KB
testcase_49 AC 86 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
using ll= long long;
using ld= long double;
using pll= pair<ll, ll>;
using vi= vector<int>;
using vl= vector<ll>;
using vd= vector<ld>;
using vs= vector<string>;
using vb= vector<bool>;
using vpll= vector<pll>;
using vvi= vector<vi>;
using vvl= vector<vl>;
using vvd= vector<vd>;
using vvs= vector<vs>;
using vvb= vector<vb>;
using vvpll= vector<vpll>;
// using mint = modint1000000007;
// using mint = modint998244353;
constexpr ll mod= 1e9 + 7;
// constexpr ll mod= 998244353;
#define ALL(x) (x).begin(), (x).end()
#define _overload(_1, _2, _3, name, ...) name
#define REPBASE(i, a, b) for(ll(i)= (a); (i) < (b); (i)++)
#define RREPBASE(i, a, b) for(ll(i)= (a); (i) >= (b); (i)--)
#define REPB(i, n) REPBASE(i, 0, n)
#define REPS(i, n) REPBASE(i, 1, n + 1)
#define RREP(i, n) RREPBASE(i, n - 1, 0)
#define RREPS(i, n) RREPBASE(i, n, 1)
#define REP(...) _overload(__VA_ARGS__, REPBASE, REPB)(__VA_ARGS__)
#define EACH(x, c) for(auto &x : c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())
#define YES(n) ((n) ? "YES" : "NO")
#define Yes(n) ((n) ? "Yes" : "No")
#define yes(n) ((n) ? "yes" : "no")
#define SZ(x) ((ll)(x).size())
#define BIT(n) (1LL << (n))
template <class T> inline bool chmax(T &a, const T &b) {
    if(a < b) {
        a= b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
    if(b < a) {
        a= b;
        return 1;
    }
    return 0;
}

/* modとる */
inline ll modu(ll a){
    return(a % mod + mod) % mod;
}

/* modつき二分累乗法 */
ll modpow(ll a, ll b) {
    ll res = 1;
    for (a = modu(a); b; a = modu(a * a) , b >>= 1){
        if (b & 1) res = modu(res * a);
    }
    return res;
}

/* 逆元(法mod = 1e9+7) */
ll modinv(ll a){
    ll b = mod, u = 1, v = 0;
    while (b){
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
        }
    return modu(u);
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    ll S;
    cin >> S;
    REP(sdfignji,S){
        ll N,M,X;
        cin >> N >> M >> X;
        ll wa = modpow(M+1,N);
        ll sa = modpow(M-1,N);
        ll ans = 0;
        if(N % 2 == 0){
            if(X == 0){
                ans = (wa + sa)*modinv(2);
            }else{
                ans = (wa - sa)*modinv(2);
            }
        }else{
            if(X == 0){
                ans = (wa - sa)*modinv(2);
            }else{
                ans = (wa + sa)*modinv(2);
            }
        }
        cout << modu(ans) << "\n";
    }
}
0