結果

問題 No.1258 コインゲーム
ユーザー kkktymkkktym
提出日時 2020-10-17 11:01:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 323 ms / 2,000 ms
コード長 2,244 bytes
コンパイル時間 940 ms
コンパイル使用メモリ 103,636 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-28 07:29:40
合計ジャッジ時間 12,515 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
4,500 KB
testcase_01 AC 69 ms
4,380 KB
testcase_02 AC 27 ms
4,380 KB
testcase_03 AC 229 ms
4,376 KB
testcase_04 AC 279 ms
4,376 KB
testcase_05 AC 44 ms
4,376 KB
testcase_06 AC 191 ms
4,380 KB
testcase_07 AC 20 ms
4,380 KB
testcase_08 AC 16 ms
4,376 KB
testcase_09 AC 92 ms
4,376 KB
testcase_10 AC 225 ms
4,380 KB
testcase_11 AC 257 ms
4,376 KB
testcase_12 AC 181 ms
4,376 KB
testcase_13 AC 56 ms
4,380 KB
testcase_14 AC 19 ms
4,376 KB
testcase_15 AC 223 ms
4,380 KB
testcase_16 AC 46 ms
4,376 KB
testcase_17 AC 251 ms
4,380 KB
testcase_18 AC 93 ms
4,376 KB
testcase_19 AC 83 ms
4,376 KB
testcase_20 AC 180 ms
4,376 KB
testcase_21 AC 238 ms
4,376 KB
testcase_22 AC 160 ms
4,380 KB
testcase_23 AC 125 ms
4,380 KB
testcase_24 AC 45 ms
4,380 KB
testcase_25 AC 113 ms
4,380 KB
testcase_26 AC 98 ms
4,380 KB
testcase_27 AC 230 ms
4,376 KB
testcase_28 AC 59 ms
4,376 KB
testcase_29 AC 63 ms
4,376 KB
testcase_30 AC 290 ms
4,376 KB
testcase_31 AC 72 ms
4,380 KB
testcase_32 AC 32 ms
4,380 KB
testcase_33 AC 189 ms
4,376 KB
testcase_34 AC 241 ms
4,380 KB
testcase_35 AC 82 ms
4,376 KB
testcase_36 AC 235 ms
4,376 KB
testcase_37 AC 91 ms
4,380 KB
testcase_38 AC 216 ms
4,376 KB
testcase_39 AC 63 ms
4,380 KB
testcase_40 AC 290 ms
4,376 KB
testcase_41 AC 282 ms
4,380 KB
testcase_42 AC 285 ms
4,376 KB
testcase_43 AC 292 ms
4,376 KB
testcase_44 AC 307 ms
4,376 KB
testcase_45 AC 291 ms
4,380 KB
testcase_46 AC 284 ms
4,380 KB
testcase_47 AC 282 ms
4,380 KB
testcase_48 AC 295 ms
4,380 KB
testcase_49 AC 323 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <limits>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
template<class T> inline int  sz(T &a) { return a.size(); }
using ll = long long; using ld = long double;
using pi = pair<int,int>; using pl = pair<ll,ll>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
const int inf = numeric_limits<int>::max();
const ll infll = numeric_limits<ll>::max();
// Modint
// modint<MOD> で宣言
template<ll MOD>
struct modint{
  ll x;
  ll mod = MOD;
  modint(ll x=0):x(x%MOD){}
  modint& operator+=(const modint a){
    if((x+=a.x)>=MOD) x-=MOD;
    return *this;
  }
  modint& operator-=(const modint a){
    if((x += MOD-a.x)>=MOD) x-=MOD;
    return *this;
  }
  modint& operator*=(const modint a){
    (x*=a.x)%=MOD;
    return *this;
  }
  modint operator+(const modint a) const{
    modint res(*this);
    return res+=a;
  }
  modint operator-(const modint a) const{
    modint res(*this);
    return res-=a;
  }
  modint operator*(const modint a) const{
    modint res(*this);
    return res*=a;
  }
  modint pow(ll t) const{
    if(!t) return 1;
    modint a = pow(t>>1);
    a*=a;
    if(t&1) a*=*this;
    return a;
  }
  
  //for prime mod
  modint inv() const{
    return pow(MOD-2);
  }
  modint& operator/=(const modint a){
    return (*this) *= a.inv();
  }
  modint operator/(const modint a) const{
    modint res(*this);
    return res/=a;
  }
};
using mint = modint<1000000007>;

int main()
{
  int s; cin >> s;
  while(s-- > 0) {
    int n,m,x; cin >> n >> m >> x;
    mint res;
    if(x == 0) {
      mint pl(1 + m), mi(1);
      mi -= (mint)m;
      res = (pl.pow(n) + mi.pow(n)) / (mint)2;
    }
    else {
      mint pl(1 + m), mi(1);
      mi -= (mint)m;
      res = (pl.pow(n) - mi.pow(n)) / (mint)2;
    }
    cout << res.x << "\n";
  }
  return 0;
}
0