結果

問題 No.1258 コインゲーム
ユーザー was_koruwas_koru
提出日時 2020-10-16 23:43:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,626 bytes
コンパイル時間 774 ms
コンパイル使用メモリ 92,940 KB
実行使用メモリ 6,568 KB
最終ジャッジ日時 2023-09-28 06:04:30
合計ジャッジ時間 11,926 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#include <queue>
#include <cstdio>
#include <cstring>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001001000
#define mod 1000000007
//#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT{
    __INIT(){
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout<<fixed<<setprecision(15);
    }
}__init;

ll mpow(ll a,ll b){
    if(b == 0) return 1;
    if(b == 1) return a%mod;
    if(b%2 == 0) return mpow((a*a)%mod,b/2)%mod;
    else return (a%mod)*mpow((a*a)%mod,(b-1)/2)%mod;
}
//necessary mpow
#define N 200000
ll fact[N+1],ifact[N+1];
void init_comb(){
    fact[0] = 1;
    ifact[0] = 1;
    rep1(i,N+1){
        fact[i] = (fact[i-1]*i)%mod;
    }
    ifact[N] = mpow(fact[N],mod-2);
    for(ll i=N;i>0;--i) ifact[i-1] = (ifact[i]*i)%mod;
}
ll mcomb(ll a,ll b){
    if(a<b) return 0;
    if(a==b) return 1;
    return (((fact[a]*ifact[b])%mod)*ifact[a-b])%mod;
}

int main(){
    ll __;
    cin>>__;
    init_comb();
    rep(_,__){
        ll n,m,x;
        cin>>n>>m>>x;
        ll ans = 0;
        rep(i,n+1){
            if(i%2 == x)
            ans = (ans+(mcomb(n,i)*mpow(m,i))%mod)%mod;
        }
        cout<<ans<<endl;
    }
}
0