結果

問題 No.1258 コインゲーム
ユーザー umezoumezo
提出日時 2020-10-16 22:50:24
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 244 ms / 2,000 ms
コード長 609 bytes
コンパイル時間 1,964 ms
コンパイル使用メモリ 199,792 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-28 04:37:51
合計ジャッジ時間 11,749 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
4,376 KB
testcase_01 AC 61 ms
4,380 KB
testcase_02 AC 22 ms
4,376 KB
testcase_03 AC 188 ms
4,376 KB
testcase_04 AC 224 ms
4,376 KB
testcase_05 AC 37 ms
4,380 KB
testcase_06 AC 156 ms
4,380 KB
testcase_07 AC 15 ms
4,376 KB
testcase_08 AC 14 ms
4,376 KB
testcase_09 AC 78 ms
4,376 KB
testcase_10 AC 187 ms
4,380 KB
testcase_11 AC 210 ms
4,380 KB
testcase_12 AC 153 ms
4,380 KB
testcase_13 AC 49 ms
4,380 KB
testcase_14 AC 17 ms
4,380 KB
testcase_15 AC 184 ms
4,384 KB
testcase_16 AC 36 ms
4,376 KB
testcase_17 AC 207 ms
4,380 KB
testcase_18 AC 76 ms
4,376 KB
testcase_19 AC 70 ms
4,380 KB
testcase_20 AC 157 ms
4,380 KB
testcase_21 AC 202 ms
4,376 KB
testcase_22 AC 138 ms
4,380 KB
testcase_23 AC 101 ms
4,380 KB
testcase_24 AC 38 ms
4,376 KB
testcase_25 AC 96 ms
4,380 KB
testcase_26 AC 81 ms
4,380 KB
testcase_27 AC 188 ms
4,380 KB
testcase_28 AC 52 ms
4,376 KB
testcase_29 AC 56 ms
4,376 KB
testcase_30 AC 238 ms
4,376 KB
testcase_31 AC 58 ms
4,376 KB
testcase_32 AC 27 ms
4,376 KB
testcase_33 AC 161 ms
4,376 KB
testcase_34 AC 200 ms
4,380 KB
testcase_35 AC 70 ms
4,376 KB
testcase_36 AC 192 ms
4,376 KB
testcase_37 AC 74 ms
4,376 KB
testcase_38 AC 179 ms
4,380 KB
testcase_39 AC 52 ms
4,376 KB
testcase_40 AC 238 ms
4,376 KB
testcase_41 AC 239 ms
4,376 KB
testcase_42 AC 236 ms
4,380 KB
testcase_43 AC 242 ms
4,380 KB
testcase_44 AC 234 ms
4,380 KB
testcase_45 AC 240 ms
4,380 KB
testcase_46 AC 244 ms
4,376 KB
testcase_47 AC 237 ms
4,376 KB
testcase_48 AC 236 ms
4,380 KB
testcase_49 AC 243 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

const ll MOD=1e9+7;
const ll A=500000004;

ll modpow(ll x,ll n){
  ll ans=1;
  while(n){
    if(n&1) ans=ans*x %MOD;
    x=x*x %MOD;
    n/=2;
  }
  return ans;
}

int main(){
  int s;
  cin>>s;
  
  while(s--){
    ll n,m;
    int x;
    cin>>n>>m>>x;
    
    if(x==0){
      cout<<(modpow(1+m,n)+modpow((1-m+MOD)%MOD,n))*A%MOD<<endl;
    }
    else{
      cout<<((modpow(1+m,n)-modpow((1-m+MOD)%MOD,n)+MOD)%MOD)*A%MOD<<endl;
    }
  }

  return 0;
}
0