結果

問題 No.1258 コインゲーム
ユーザー wakapaijazzwakapaijazz
提出日時 2020-10-16 22:12:08
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 229 ms / 2,000 ms
コード長 2,821 bytes
コンパイル時間 2,311 ms
コンパイル使用メモリ 204,684 KB
実行使用メモリ 6,280 KB
最終ジャッジ日時 2023-09-28 03:25:11
合計ジャッジ時間 11,893 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
5,976 KB
testcase_01 AC 56 ms
6,264 KB
testcase_02 AC 23 ms
6,084 KB
testcase_03 AC 171 ms
5,968 KB
testcase_04 AC 193 ms
6,128 KB
testcase_05 AC 34 ms
6,060 KB
testcase_06 AC 143 ms
6,080 KB
testcase_07 AC 20 ms
6,124 KB
testcase_08 AC 16 ms
6,132 KB
testcase_09 AC 71 ms
6,204 KB
testcase_10 AC 170 ms
6,132 KB
testcase_11 AC 196 ms
6,140 KB
testcase_12 AC 138 ms
6,196 KB
testcase_13 AC 47 ms
6,136 KB
testcase_14 AC 17 ms
6,148 KB
testcase_15 AC 168 ms
6,148 KB
testcase_16 AC 37 ms
5,984 KB
testcase_17 AC 187 ms
6,108 KB
testcase_18 AC 72 ms
6,108 KB
testcase_19 AC 67 ms
6,088 KB
testcase_20 AC 143 ms
6,120 KB
testcase_21 AC 184 ms
6,040 KB
testcase_22 AC 131 ms
6,012 KB
testcase_23 AC 95 ms
6,208 KB
testcase_24 AC 39 ms
6,068 KB
testcase_25 AC 93 ms
6,060 KB
testcase_26 AC 81 ms
6,196 KB
testcase_27 AC 177 ms
6,104 KB
testcase_28 AC 49 ms
6,084 KB
testcase_29 AC 52 ms
5,968 KB
testcase_30 AC 219 ms
6,260 KB
testcase_31 AC 59 ms
6,084 KB
testcase_32 AC 28 ms
6,044 KB
testcase_33 AC 144 ms
6,136 KB
testcase_34 AC 184 ms
6,204 KB
testcase_35 AC 72 ms
6,152 KB
testcase_36 AC 182 ms
5,972 KB
testcase_37 AC 74 ms
6,200 KB
testcase_38 AC 169 ms
6,088 KB
testcase_39 AC 49 ms
5,968 KB
testcase_40 AC 209 ms
6,064 KB
testcase_41 AC 222 ms
6,088 KB
testcase_42 AC 217 ms
6,128 KB
testcase_43 AC 212 ms
6,200 KB
testcase_44 AC 222 ms
5,976 KB
testcase_45 AC 222 ms
6,204 KB
testcase_46 AC 212 ms
6,280 KB
testcase_47 AC 215 ms
5,964 KB
testcase_48 AC 229 ms
6,012 KB
testcase_49 AC 224 ms
6,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

/*** mod int ***/

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

/*** mod int ここまで ***/

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(200005);

void Main(){
    int s; cin >> s;
    while(s--){
        int n, m, x; cin >> n >> m >> x;
        mint ans = mint(m+1).pow(n);
        mint ans2 = mint(-m+1).pow(n);
        if(x == 0){
            ans += ans2;
            ans /= 2;
            cout << ans << endl;
        }else{
            ans -= ans2;
            ans /= 2;
            cout << ans << endl;
        }
    }
    
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}
0