結果

問題 No.1258 コインゲーム
ユーザー 19iso19iso
提出日時 2020-10-16 22:34:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 252 ms / 2,000 ms
コード長 964 bytes
コンパイル時間 1,301 ms
コンパイル使用メモリ 164,304 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-28 04:20:18
合計ジャッジ時間 11,398 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
4,376 KB
testcase_01 AC 59 ms
4,380 KB
testcase_02 AC 22 ms
4,376 KB
testcase_03 AC 190 ms
4,380 KB
testcase_04 AC 216 ms
4,384 KB
testcase_05 AC 35 ms
4,376 KB
testcase_06 AC 156 ms
4,380 KB
testcase_07 AC 16 ms
4,376 KB
testcase_08 AC 14 ms
4,376 KB
testcase_09 AC 79 ms
4,376 KB
testcase_10 AC 188 ms
4,380 KB
testcase_11 AC 206 ms
4,380 KB
testcase_12 AC 150 ms
4,376 KB
testcase_13 AC 46 ms
4,380 KB
testcase_14 AC 17 ms
4,376 KB
testcase_15 AC 192 ms
4,376 KB
testcase_16 AC 37 ms
4,376 KB
testcase_17 AC 211 ms
4,376 KB
testcase_18 AC 77 ms
4,380 KB
testcase_19 AC 70 ms
4,376 KB
testcase_20 AC 154 ms
4,376 KB
testcase_21 AC 196 ms
4,376 KB
testcase_22 AC 134 ms
4,380 KB
testcase_23 AC 101 ms
4,376 KB
testcase_24 AC 36 ms
4,380 KB
testcase_25 AC 98 ms
4,376 KB
testcase_26 AC 82 ms
4,376 KB
testcase_27 AC 192 ms
4,376 KB
testcase_28 AC 51 ms
4,376 KB
testcase_29 AC 58 ms
4,380 KB
testcase_30 AC 236 ms
4,376 KB
testcase_31 AC 61 ms
4,380 KB
testcase_32 AC 26 ms
4,376 KB
testcase_33 AC 157 ms
4,380 KB
testcase_34 AC 196 ms
4,376 KB
testcase_35 AC 69 ms
4,380 KB
testcase_36 AC 205 ms
4,376 KB
testcase_37 AC 72 ms
4,380 KB
testcase_38 AC 180 ms
4,380 KB
testcase_39 AC 52 ms
4,384 KB
testcase_40 AC 252 ms
4,376 KB
testcase_41 AC 237 ms
4,380 KB
testcase_42 AC 240 ms
4,376 KB
testcase_43 AC 238 ms
4,376 KB
testcase_44 AC 247 ms
4,380 KB
testcase_45 AC 248 ms
4,380 KB
testcase_46 AC 235 ms
4,380 KB
testcase_47 AC 241 ms
4,380 KB
testcase_48 AC 245 ms
4,380 KB
testcase_49 AC 242 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define INF 1e18
#define MOD 998244353
int mod_pow(int x,int n,int mod){
    int res=1;
    while(n>0){
        if(n&1)res=res*x%mod;
        x=x*x%mod;
        n>>=1;
    }
    return res;
}
int solve(int N,int M,int X){
    int res;
    int x=mod_pow(M+1,N,1000000007),y=mod_pow(M-1,N,1000000007);
    if(X==0){
        if(N%2==0){
            res=x+y;
        }else{
            res=x-y;
        }
    }else{
        if(N%2==0){
            res=x-y;
        }else{
            res=x+y;
        }
    }
    if(res%2==0)res/=2;
    else {
        res=(res+1000000007)/2;
    }
    res=(res+1000000007)%1000000007;
    return res;
}
signed main(){
    int S;cin>>S;
    rep(i,S){
        int N,M,X;cin>>N>>M>>X;
        cout<<solve(N,M,X)<<endl;
    }
    
}
0