結果

問題 No.1258 コインゲーム
ユーザー takumi152takumi152
提出日時 2020-10-16 23:06:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 1,191 bytes
コンパイル時間 983 ms
コンパイル使用メモリ 95,980 KB
実行使用メモリ 6,276 KB
最終ジャッジ日時 2023-09-28 05:05:44
合計ジャッジ時間 9,844 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
4,376 KB
testcase_01 AC 47 ms
4,376 KB
testcase_02 AC 18 ms
4,380 KB
testcase_03 AC 151 ms
5,436 KB
testcase_04 AC 172 ms
5,680 KB
testcase_05 AC 29 ms
4,376 KB
testcase_06 AC 123 ms
5,244 KB
testcase_07 AC 14 ms
4,376 KB
testcase_08 AC 12 ms
4,380 KB
testcase_09 AC 64 ms
4,380 KB
testcase_10 AC 152 ms
5,320 KB
testcase_11 AC 168 ms
5,720 KB
testcase_12 AC 122 ms
4,944 KB
testcase_13 AC 38 ms
4,376 KB
testcase_14 AC 13 ms
4,380 KB
testcase_15 AC 147 ms
5,588 KB
testcase_16 AC 30 ms
4,380 KB
testcase_17 AC 166 ms
5,704 KB
testcase_18 AC 63 ms
4,376 KB
testcase_19 AC 57 ms
4,380 KB
testcase_20 AC 123 ms
4,908 KB
testcase_21 AC 157 ms
5,852 KB
testcase_22 AC 106 ms
4,832 KB
testcase_23 AC 80 ms
4,396 KB
testcase_24 AC 31 ms
4,376 KB
testcase_25 AC 77 ms
4,380 KB
testcase_26 AC 66 ms
4,380 KB
testcase_27 AC 150 ms
5,416 KB
testcase_28 AC 39 ms
4,380 KB
testcase_29 AC 43 ms
4,380 KB
testcase_30 AC 189 ms
5,996 KB
testcase_31 AC 48 ms
4,376 KB
testcase_32 AC 22 ms
4,376 KB
testcase_33 AC 126 ms
5,128 KB
testcase_34 AC 157 ms
5,680 KB
testcase_35 AC 55 ms
4,380 KB
testcase_36 AC 153 ms
5,344 KB
testcase_37 AC 60 ms
4,376 KB
testcase_38 AC 143 ms
5,348 KB
testcase_39 AC 41 ms
4,380 KB
testcase_40 AC 191 ms
6,240 KB
testcase_41 AC 185 ms
6,148 KB
testcase_42 AC 189 ms
6,140 KB
testcase_43 AC 185 ms
6,152 KB
testcase_44 AC 190 ms
6,220 KB
testcase_45 AC 190 ms
6,092 KB
testcase_46 AC 189 ms
6,228 KB
testcase_47 AC 190 ms
6,092 KB
testcase_48 AC 190 ms
6,276 KB
testcase_49 AC 190 ms
6,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <map>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

ll modpow(ll a, ll b, ll m = mod) {
  ll r = 1;
  while (b > 0) {
    if (b & 1) r = (r * a) % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return r;
}

ll modinv(ll x, ll m = mod) {
  ll b = m;
  ll u = 1;
  ll v = 0;
  ll tmp;
  while (b) {
    ll t = x / b;
    x -= t * b;
    tmp = x;
    x = b;
    b = tmp;
    u -= t * v;
    tmp = u;
    u = v;
    v = tmp;
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int s;
  cin >> s;
  vector<ll> n(s), m(s), x(s);
  for (int i = 0; i < s; i++) cin >> n[i] >> m[i] >> x[i];

  vector<ll> ans(s);
  for (int i = 0; i < s; i++) {
    if (x[i]) ans[i] = ((modpow(m[i]+1, n[i]) - modpow(1-m[i], n[i])) % mod * modinv(2)) % mod;
    else ans[i] = ((modpow(1-m[i], n[i]) + modpow(m[i]+1, n[i])) % mod * modinv(2)) % mod;
    if (ans[i] < 0) ans[i] += mod;
  }

  for (auto &y: ans) cout << y << endl;

  return 0;
}
0