結果

問題 No.1258 コインゲーム
ユーザー Example0911Example0911
提出日時 2020-10-16 22:25:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 310 ms / 2,000 ms
コード長 1,580 bytes
コンパイル時間 1,838 ms
コンパイル使用メモリ 201,332 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-28 03:49:20
合計ジャッジ時間 13,817 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
4,376 KB
testcase_01 AC 75 ms
4,380 KB
testcase_02 AC 27 ms
4,380 KB
testcase_03 AC 245 ms
4,376 KB
testcase_04 AC 276 ms
4,376 KB
testcase_05 AC 45 ms
4,376 KB
testcase_06 AC 202 ms
4,376 KB
testcase_07 AC 21 ms
4,380 KB
testcase_08 AC 18 ms
4,380 KB
testcase_09 AC 99 ms
4,380 KB
testcase_10 AC 244 ms
4,376 KB
testcase_11 AC 268 ms
4,376 KB
testcase_12 AC 196 ms
4,376 KB
testcase_13 AC 59 ms
4,380 KB
testcase_14 AC 19 ms
4,376 KB
testcase_15 AC 236 ms
4,376 KB
testcase_16 AC 47 ms
4,376 KB
testcase_17 AC 267 ms
4,380 KB
testcase_18 AC 99 ms
4,384 KB
testcase_19 AC 91 ms
4,376 KB
testcase_20 AC 200 ms
4,376 KB
testcase_21 AC 249 ms
4,376 KB
testcase_22 AC 176 ms
4,380 KB
testcase_23 AC 129 ms
4,380 KB
testcase_24 AC 48 ms
4,376 KB
testcase_25 AC 124 ms
4,380 KB
testcase_26 AC 106 ms
4,380 KB
testcase_27 AC 247 ms
4,376 KB
testcase_28 AC 64 ms
4,380 KB
testcase_29 AC 72 ms
4,376 KB
testcase_30 AC 304 ms
4,376 KB
testcase_31 AC 76 ms
4,380 KB
testcase_32 AC 33 ms
4,376 KB
testcase_33 AC 200 ms
4,376 KB
testcase_34 AC 256 ms
4,376 KB
testcase_35 AC 87 ms
4,376 KB
testcase_36 AC 250 ms
4,376 KB
testcase_37 AC 97 ms
4,376 KB
testcase_38 AC 234 ms
4,376 KB
testcase_39 AC 65 ms
4,376 KB
testcase_40 AC 306 ms
4,380 KB
testcase_41 AC 301 ms
4,376 KB
testcase_42 AC 301 ms
4,376 KB
testcase_43 AC 309 ms
4,380 KB
testcase_44 AC 306 ms
4,380 KB
testcase_45 AC 304 ms
4,376 KB
testcase_46 AC 304 ms
4,380 KB
testcase_47 AC 304 ms
4,376 KB
testcase_48 AC 307 ms
4,380 KB
testcase_49 AC 310 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
//#include <atcoder/all>

using namespace std;
//using namespace atcoder;

//#define int long long
#define ll long long
ll INF = (1LL << 60);
constexpr int mod = 1000000007;
using P = pair<int, int>;
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 {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= 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 {
		mint res(*this);
		return res /= a;
	}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
signed main() {
	int s; cin >> s;
	for (int _ = 0; _ < s; _++) {
		ll n, m, x; cin >> n >> m >> x;
		mint ans = mint(1 - m).pow(n) + mint(m + 1).pow(n);
		ans /= 2;
		if (x % 2 == 1) {
			ans = mint(m + 1).pow(n) - ans;
		}
		cout << ans << endl;
	}
	return 0;
}
0