結果
| 問題 |
No.1258 コインゲーム
|
| コンテスト | |
| ユーザー |
Example0911
|
| 提出日時 | 2020-10-16 22:25:36 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 354 ms / 2,000 ms |
| コード長 | 1,580 bytes |
| コンパイル時間 | 1,984 ms |
| コンパイル使用メモリ | 195,948 KB |
| 最終ジャッジ日時 | 2025-01-15 08:45:56 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 50 |
ソースコード
#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;
}
Example0911