結果

問題 No.1258 コインゲーム
ユーザー どららどらら
提出日時 2020-10-17 00:34:41
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 334 ms / 2,000 ms
コード長 2,378 bytes
コンパイル時間 1,644 ms
コンパイル使用メモリ 171,588 KB
実行使用メモリ 34,436 KB
最終ジャッジ日時 2023-09-28 07:06:34
合計ジャッジ時間 16,306 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
34,244 KB
testcase_01 AC 103 ms
34,140 KB
testcase_02 AC 57 ms
34,064 KB
testcase_03 AC 266 ms
34,192 KB
testcase_04 AC 297 ms
34,360 KB
testcase_05 AC 74 ms
34,360 KB
testcase_06 AC 223 ms
34,196 KB
testcase_07 AC 50 ms
34,084 KB
testcase_08 AC 48 ms
34,380 KB
testcase_09 AC 128 ms
34,364 KB
testcase_10 AC 265 ms
34,380 KB
testcase_11 AC 290 ms
34,248 KB
testcase_12 AC 217 ms
34,288 KB
testcase_13 AC 89 ms
34,188 KB
testcase_14 AC 50 ms
34,288 KB
testcase_15 AC 260 ms
34,364 KB
testcase_16 AC 76 ms
34,248 KB
testcase_17 AC 290 ms
34,068 KB
testcase_18 AC 128 ms
34,188 KB
testcase_19 AC 118 ms
34,184 KB
testcase_20 AC 220 ms
34,244 KB
testcase_21 AC 273 ms
34,256 KB
testcase_22 AC 201 ms
34,360 KB
testcase_23 AC 155 ms
34,120 KB
testcase_24 AC 78 ms
34,188 KB
testcase_25 AC 149 ms
34,260 KB
testcase_26 AC 132 ms
34,424 KB
testcase_27 AC 265 ms
34,128 KB
testcase_28 AC 93 ms
34,144 KB
testcase_29 AC 98 ms
34,364 KB
testcase_30 AC 327 ms
34,364 KB
testcase_31 AC 104 ms
34,132 KB
testcase_32 AC 63 ms
34,252 KB
testcase_33 AC 226 ms
34,192 KB
testcase_34 AC 275 ms
34,428 KB
testcase_35 AC 115 ms
34,256 KB
testcase_36 AC 271 ms
34,140 KB
testcase_37 AC 122 ms
34,136 KB
testcase_38 AC 256 ms
34,308 KB
testcase_39 AC 94 ms
34,248 KB
testcase_40 AC 334 ms
34,384 KB
testcase_41 AC 334 ms
34,364 KB
testcase_42 AC 330 ms
34,328 KB
testcase_43 AC 328 ms
34,136 KB
testcase_44 AC 331 ms
34,376 KB
testcase_45 AC 332 ms
34,436 KB
testcase_46 AC 331 ms
34,256 KB
testcase_47 AC 333 ms
34,424 KB
testcase_48 AC 332 ms
34,184 KB
testcase_49 AC 333 ms
34,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

static const long long mod = 1000000007;
struct mint {
  long long x;
  mint(ll x = 0):x(x%mod) {}
  //mint(ll x = 0):x((x%mod+mod)%mod) {} // for minus
  mint& operator+=(const mint a) {
    (x += a.x) %= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    (x += mod-a.x) %= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint ret(*this);
    return ret += a;
  }
  mint operator-(const mint a) const {
    mint ret(*this);
    return ret -= a;
  }
  mint operator*(const mint a) const {
    mint ret(*this);
    return ret *= a;
  }
  mint pow(ll t) const {
    if(t==0) return mint(1);
    mint a = pow(t>>1);
    a *= a;
    if(t&1) a *= *this;
    return a;
  }
  
  //for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint ret(*this);
    return ret /= a;
  }
};
ostream &operator<<(ostream& os, const mint& x) {
  os << x.x;
  return os;
}
bool operator==(const mint& a, const mint& b){
  return a.x == b.x;
}
class modutils {
  vector<mint> fact, invfact;
public:
  modutils(int n = 2000005):fact(n+1),invfact(n+1) {
    fact[0] = 1;
    for(int i=1; i<=n; i++) fact[i] = fact[i-1] * i;
    invfact[n] = fact[n].inv();
    for(int i=n; i>=1; i--) invfact[i-1] = invfact[i] * i;
  }
  mint pow(mint x, ll n) {
    return x.pow(n);
  }
  mint comb(ll n, ll k) {
    if(n<0 || k<0 || n<k) return 0;
    return fact[n] * invfact[k] * invfact[n-k];
  }
  mint perm(ll n, ll k) {
    if(n<0 || k<0 || n<k) return 0;
    return fact[n] * invfact[n-k];
  }
  mint fac(ll n) {
    return fact[n];
  }
};
modutils mutil;

void solve(){
  ll N, M, X;
  cin >> N >> M >> X;

  mint ret(0);
  if(X%2 == 0){
    ret += (mint(1-M+mod).pow(N) + mint(M+1).pow(N))/2;
  }else{
    ret += (mint(M+1).pow(N) - mint(1-M+mod).pow(N))/2;
  }
  cout << ret << endl;
}


int main(){

  int S;
  cin >> S;
  rep(i,S){
    solve();
  }
  
  return 0;
}

0