結果
| 問題 |
No.1258 コインゲーム
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-10-16 22:38:11 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 245 ms / 2,000 ms |
| コード長 | 1,184 bytes |
| コンパイル時間 | 775 ms |
| コンパイル使用メモリ | 92,756 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 22:56:24 |
| 合計ジャッジ時間 | 10,375 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 50 |
ソースコード
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
long long x = 2;
long long y = 1000000005;
long long two = 1;
while (y > 0) {
if ((y & 1) == 1) {
two = two * x % 1000000007;
}
x = x * x % 1000000007;
y >>= 1;
}
int s;
cin >> s;
for (int i = 0; i < s; i++) {
long long n, m, x1;
cin >> n >> m >> x1;
x = m + 1;
y = n;
long long ans = 1;
while (y > 0) {
if ((y & 1) == 1) {
ans = ans * x % 1000000007;
}
x = x * x % 1000000007;
y >>= 1;
}
x = m - 1;
y = n;
long long ans1 = 1;
while (y > 0) {
if ((y & 1) == 1) {
ans1 = ans1 * x % 1000000007;
}
x = x * x % 1000000007;
y >>= 1;
}
long long ans2 = ans;
ans -= ans1;
ans %= 1000000007;
if (ans < 0)ans += 1000000007;
ans = ans * two % 1000000007;
if (n % 2 == x1) {
ans = ans2 - ans;
ans %= 1000000007;
if (ans < 0)ans += 1000000007;
}
cout << ans % 1000000007 << endl;
}
return 0;
}