結果

問題 No.1258 コインゲーム
ユーザー carrot46carrot46
提出日時 2020-10-16 22:01:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 250 ms / 2,000 ms
コード長 2,482 bytes
コンパイル時間 1,318 ms
コンパイル使用メモリ 166,116 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-28 03:05:32
合計ジャッジ時間 11,192 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
4,380 KB
testcase_01 AC 59 ms
4,376 KB
testcase_02 AC 22 ms
4,380 KB
testcase_03 AC 194 ms
4,376 KB
testcase_04 AC 211 ms
4,376 KB
testcase_05 AC 36 ms
4,376 KB
testcase_06 AC 162 ms
4,380 KB
testcase_07 AC 16 ms
4,376 KB
testcase_08 AC 13 ms
4,376 KB
testcase_09 AC 78 ms
4,380 KB
testcase_10 AC 187 ms
4,380 KB
testcase_11 AC 205 ms
4,380 KB
testcase_12 AC 154 ms
4,376 KB
testcase_13 AC 47 ms
4,376 KB
testcase_14 AC 16 ms
4,376 KB
testcase_15 AC 179 ms
4,380 KB
testcase_16 AC 38 ms
4,380 KB
testcase_17 AC 207 ms
4,384 KB
testcase_18 AC 77 ms
4,376 KB
testcase_19 AC 72 ms
4,380 KB
testcase_20 AC 154 ms
4,376 KB
testcase_21 AC 194 ms
4,376 KB
testcase_22 AC 137 ms
4,380 KB
testcase_23 AC 101 ms
4,376 KB
testcase_24 AC 36 ms
4,380 KB
testcase_25 AC 97 ms
4,376 KB
testcase_26 AC 83 ms
4,380 KB
testcase_27 AC 191 ms
4,380 KB
testcase_28 AC 51 ms
4,380 KB
testcase_29 AC 53 ms
4,380 KB
testcase_30 AC 238 ms
4,380 KB
testcase_31 AC 58 ms
4,380 KB
testcase_32 AC 26 ms
4,380 KB
testcase_33 AC 158 ms
4,376 KB
testcase_34 AC 196 ms
4,376 KB
testcase_35 AC 68 ms
4,380 KB
testcase_36 AC 196 ms
4,384 KB
testcase_37 AC 76 ms
4,380 KB
testcase_38 AC 176 ms
4,380 KB
testcase_39 AC 51 ms
4,376 KB
testcase_40 AC 247 ms
4,376 KB
testcase_41 AC 241 ms
4,380 KB
testcase_42 AC 242 ms
4,376 KB
testcase_43 AC 239 ms
4,380 KB
testcase_44 AC 241 ms
4,376 KB
testcase_45 AC 250 ms
4,376 KB
testcase_46 AC 240 ms
4,376 KB
testcase_47 AC 241 ms
4,376 KB
testcase_48 AC 241 ms
4,380 KB
testcase_49 AC 242 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("O3")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second

using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

ll N,M,H,W,Q,K,A,B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL<<48);

template <unsigned long long mod > class modint{
public:
    ll x;
    constexpr modint(){x = 0;}
    constexpr modint(ll _x) : x((_x < 0 ? ((_x += (LLONG_MAX / mod) * mod) < 0 ? _x + (LLONG_MAX / mod) * mod : _x) : _x)%mod){}
    constexpr modint set_raw(ll _x){
        //_x in [0, mod)
        x = _x;
        return *this;
    }
    constexpr modint operator-(){
        return x == 0 ? 0 : mod - x;
    }
    constexpr modint& operator+=(const modint& a){
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr modint operator+(const modint& a) const{
        return modint(*this) += a;
    }
    constexpr modint& operator-=(const modint& a){
        if((x -= a.x) < 0) x += mod;
        return *this;
    }
    constexpr modint operator-(const modint& a) const{
        return modint(*this) -= a;
    }
    constexpr modint& operator*=(const modint& a){
        (x *= a.x)%=mod;
        return *this;
    }
    constexpr modint operator*(const modint& a) const{
        return modint(*this) *= a;
    }
    constexpr modint pow(unsigned long long pw) const{
        modint res(1), comp(*this);
        while(pw){
            if(pw&1) res *= comp;
            comp *= comp;
            pw >>= 1;
        }
        return res;
    }
    //以下、modが素数のときのみ
    constexpr modint inv() const{
        if(x == 2) return (mod + 1) >> 1;
        return modint(*this).pow(mod - 2);
    }
    constexpr modint& operator/=(const modint &a){
        (x *= a.inv().x)%=mod;
        return *this;
    }
    constexpr modint operator/(const modint &a) const{
        return modint(*this) /= a;
    }
};
#define mod2 1000000007
using mint = modint<mod2>;

ostream& operator<<(ostream& os, const mint& a){
    os << a.x;
    return os;
}
using vm = vector<mint>;

int main() {
    cin>>Q;
    rep(_, Q){
        cin>>N>>M>>K;
        mint res;
        res = (mint(1 + M).pow(N) + mint(1 - M).pow(N) * (K ? -1 : 1)) * ((mod2 + 1)>>1);
        cout<<res<<endl;
    }
}
0