結果

問題 No.1258 コインゲーム
ユーザー hiro71687khiro71687k
提出日時 2023-03-29 02:35:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 611 ms / 2,000 ms
コード長 1,072 bytes
コンパイル時間 4,557 ms
コンパイル使用メモリ 262,516 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-20 18:54:45
合計ジャッジ時間 25,761 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
4,352 KB
testcase_01 AC 143 ms
4,352 KB
testcase_02 AC 54 ms
4,352 KB
testcase_03 AC 472 ms
4,352 KB
testcase_04 AC 533 ms
4,352 KB
testcase_05 AC 86 ms
4,352 KB
testcase_06 AC 386 ms
4,352 KB
testcase_07 AC 39 ms
4,352 KB
testcase_08 AC 34 ms
4,352 KB
testcase_09 AC 192 ms
4,352 KB
testcase_10 AC 463 ms
4,352 KB
testcase_11 AC 517 ms
4,352 KB
testcase_12 AC 382 ms
4,352 KB
testcase_13 AC 117 ms
4,352 KB
testcase_14 AC 38 ms
4,352 KB
testcase_15 AC 453 ms
4,352 KB
testcase_16 AC 90 ms
4,352 KB
testcase_17 AC 513 ms
4,352 KB
testcase_18 AC 190 ms
4,352 KB
testcase_19 AC 174 ms
4,352 KB
testcase_20 AC 381 ms
4,352 KB
testcase_21 AC 487 ms
4,352 KB
testcase_22 AC 338 ms
4,352 KB
testcase_23 AC 251 ms
4,352 KB
testcase_24 AC 93 ms
4,352 KB
testcase_25 AC 239 ms
4,352 KB
testcase_26 AC 201 ms
4,352 KB
testcase_27 AC 471 ms
4,352 KB
testcase_28 AC 123 ms
4,352 KB
testcase_29 AC 132 ms
4,352 KB
testcase_30 AC 589 ms
4,352 KB
testcase_31 AC 147 ms
4,352 KB
testcase_32 AC 65 ms
4,352 KB
testcase_33 AC 390 ms
4,352 KB
testcase_34 AC 491 ms
4,352 KB
testcase_35 AC 170 ms
4,352 KB
testcase_36 AC 476 ms
4,352 KB
testcase_37 AC 185 ms
4,352 KB
testcase_38 AC 450 ms
4,352 KB
testcase_39 AC 126 ms
4,352 KB
testcase_40 AC 609 ms
4,352 KB
testcase_41 AC 606 ms
4,352 KB
testcase_42 AC 611 ms
4,352 KB
testcase_43 AC 608 ms
4,352 KB
testcase_44 AC 608 ms
4,352 KB
testcase_45 AC 608 ms
4,352 KB
testcase_46 AC 607 ms
4,352 KB
testcase_47 AC 604 ms
4,352 KB
testcase_48 AC 606 ms
4,352 KB
testcase_49 AC 605 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
using ld=long double;
ld pie=3.141592653589793;
ll inf=14449999999999994;
ll mod=1000000007;
ll modpow(ll x, ll n) {
  x = x%mod;
  if(n==0) return 1;  //再帰の終了条件

  else if(n%2==1) {
    return (x*modpow(x, n-1))%mod;  //nが奇数ならnを1ずらす
  }
  else return modpow((x*x)%mod, n/2)%mod;  //nが偶数ならnが半分になる
}
int main(){
    ll s;
    cin >> s;
    for (ll o = 0; o < s; o++)
    {
        ll n,m,x;
        cin >> n >> m >> x;
        ll y=modpow(1+m,n);
        ll z=modpow(1-m,n);
        if (x==0)
        {
            ll ans=y+z;
            ans%=mod;
            ans+=mod;
            ans%=mod;
            ans*=inv_mod(2,mod);
            ans%=mod;
            cout << ans << endl;
        }else{
            ll ans=y-z;
            ans%=mod;
            ans+=mod;
            ans%=mod;
            ans*=inv_mod(2,mod);
            ans%=mod;
            cout << ans << endl;
        }
        
    }
    
}
0