結果

問題 No.1258 コインゲーム
ユーザー motmot
提出日時 2020-10-17 04:06:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 472 ms / 2,000 ms
コード長 1,022 bytes
コンパイル時間 630 ms
コンパイル使用メモリ 84,744 KB
実行使用メモリ 4,436 KB
最終ジャッジ日時 2023-09-28 07:20:53
合計ジャッジ時間 16,851 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
4,376 KB
testcase_01 AC 94 ms
4,376 KB
testcase_02 AC 37 ms
4,380 KB
testcase_03 AC 321 ms
4,380 KB
testcase_04 AC 359 ms
4,376 KB
testcase_05 AC 59 ms
4,380 KB
testcase_06 AC 270 ms
4,380 KB
testcase_07 AC 27 ms
4,380 KB
testcase_08 AC 23 ms
4,380 KB
testcase_09 AC 130 ms
4,376 KB
testcase_10 AC 310 ms
4,380 KB
testcase_11 AC 346 ms
4,376 KB
testcase_12 AC 259 ms
4,376 KB
testcase_13 AC 81 ms
4,376 KB
testcase_14 AC 27 ms
4,376 KB
testcase_15 AC 322 ms
4,380 KB
testcase_16 AC 61 ms
4,376 KB
testcase_17 AC 353 ms
4,376 KB
testcase_18 AC 129 ms
4,380 KB
testcase_19 AC 120 ms
4,376 KB
testcase_20 AC 253 ms
4,380 KB
testcase_21 AC 326 ms
4,376 KB
testcase_22 AC 245 ms
4,380 KB
testcase_23 AC 172 ms
4,380 KB
testcase_24 AC 65 ms
4,380 KB
testcase_25 AC 161 ms
4,380 KB
testcase_26 AC 139 ms
4,376 KB
testcase_27 AC 330 ms
4,380 KB
testcase_28 AC 85 ms
4,376 KB
testcase_29 AC 91 ms
4,380 KB
testcase_30 AC 391 ms
4,380 KB
testcase_31 AC 98 ms
4,376 KB
testcase_32 AC 44 ms
4,380 KB
testcase_33 AC 267 ms
4,376 KB
testcase_34 AC 337 ms
4,376 KB
testcase_35 AC 112 ms
4,376 KB
testcase_36 AC 327 ms
4,380 KB
testcase_37 AC 125 ms
4,380 KB
testcase_38 AC 302 ms
4,380 KB
testcase_39 AC 85 ms
4,376 KB
testcase_40 AC 457 ms
4,380 KB
testcase_41 AC 445 ms
4,380 KB
testcase_42 AC 466 ms
4,376 KB
testcase_43 AC 450 ms
4,380 KB
testcase_44 AC 456 ms
4,376 KB
testcase_45 AC 449 ms
4,380 KB
testcase_46 AC 466 ms
4,380 KB
testcase_47 AC 460 ms
4,380 KB
testcase_48 AC 472 ms
4,376 KB
testcase_49 AC 463 ms
4,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

ll mypow(ll a, ll b) {
  ll ans = 1;
  ll two;
  ll tmp;
  while(b>0) {
    two = 1;
    tmp = a;
    while(2*two<b) {
      two *= 2;
      tmp *= tmp;
      tmp %= mod;
    }
    b -= two;
    ans *= tmp;
    ans %= mod;
  }
  return ans;
}

int main() {
  int S;
  cin>>S;
  ll ans[S];
  ll N, M, X;
  for(int i=0;i<S;++i) {
    cin>>N>>M>>X;
    if(X==1) ans[i] = (mypow(1+M, N)-mypow(1-M+mod, N)+mod)%mod*mypow(2, mod-2)%mod;
    else ans[i] = (mypow(1+M, N)+mypow(1-M+mod, N))%mod*mypow(2, mod-2)%mod;
  }
  for(int i=0;i<S;++i) cout<<ans[i]<<endl;
}

0