結果

問題 No.1258 コインゲーム
ユーザー hanbei_dayohanbei_dayo
提出日時 2020-10-17 12:33:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 289 ms / 2,000 ms
コード長 916 bytes
コンパイル時間 1,478 ms
コンパイル使用メモリ 166,708 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-28 07:36:47
合計ジャッジ時間 13,055 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
4,380 KB
testcase_01 AC 70 ms
4,380 KB
testcase_02 AC 26 ms
4,380 KB
testcase_03 AC 226 ms
4,376 KB
testcase_04 AC 257 ms
4,376 KB
testcase_05 AC 41 ms
4,376 KB
testcase_06 AC 186 ms
4,380 KB
testcase_07 AC 20 ms
4,376 KB
testcase_08 AC 17 ms
4,376 KB
testcase_09 AC 93 ms
4,376 KB
testcase_10 AC 224 ms
4,376 KB
testcase_11 AC 249 ms
4,376 KB
testcase_12 AC 180 ms
4,380 KB
testcase_13 AC 56 ms
4,376 KB
testcase_14 AC 19 ms
4,384 KB
testcase_15 AC 216 ms
4,380 KB
testcase_16 AC 44 ms
4,376 KB
testcase_17 AC 245 ms
4,376 KB
testcase_18 AC 91 ms
4,376 KB
testcase_19 AC 83 ms
4,376 KB
testcase_20 AC 182 ms
4,380 KB
testcase_21 AC 233 ms
4,376 KB
testcase_22 AC 162 ms
4,376 KB
testcase_23 AC 120 ms
4,380 KB
testcase_24 AC 45 ms
4,380 KB
testcase_25 AC 114 ms
4,376 KB
testcase_26 AC 98 ms
4,376 KB
testcase_27 AC 226 ms
4,376 KB
testcase_28 AC 60 ms
4,380 KB
testcase_29 AC 64 ms
4,376 KB
testcase_30 AC 280 ms
4,376 KB
testcase_31 AC 72 ms
4,376 KB
testcase_32 AC 32 ms
4,376 KB
testcase_33 AC 187 ms
4,376 KB
testcase_34 AC 233 ms
4,376 KB
testcase_35 AC 81 ms
4,380 KB
testcase_36 AC 228 ms
4,380 KB
testcase_37 AC 89 ms
4,380 KB
testcase_38 AC 213 ms
4,380 KB
testcase_39 AC 61 ms
4,380 KB
testcase_40 AC 284 ms
4,380 KB
testcase_41 AC 280 ms
4,376 KB
testcase_42 AC 280 ms
4,380 KB
testcase_43 AC 287 ms
4,380 KB
testcase_44 AC 286 ms
4,376 KB
testcase_45 AC 289 ms
4,380 KB
testcase_46 AC 286 ms
4,380 KB
testcase_47 AC 289 ms
4,376 KB
testcase_48 AC 287 ms
4,376 KB
testcase_49 AC 280 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define N (1000000000+7)
//#define N 998244353
#define INF 1e18
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
const int inf = (int)1e9; 

ll inv(ll x,ll power) {
	ll res = 1;
	ll k = power;
	ll y = x%N;
	while (k) {
		if (k & 1)res = (res*y) % N;
		y = (y%N*y%N) % N;
		k /= 2;
	}
	return res;
}

int main(void){
    int S;
    cin>>S;
    while(S--){
        ll n,m,x;
        cin>>n>>m>>x;
        ll INV = inv(2LL,N-2);
        ll ans1 = (inv(m+1,n)+inv(m-1,n))%N;
        ans1 = (ans1+N)%N;
        ans1= (ans1*INV)%N;
        ll ans2 = (inv(m+1,n)-inv(m-1,n))%N;
        ans2 = (ans2+N)%N;
        ans2 = (ans2*INV)%N;
        if(n%2==0){
            if(x==0)cout<<ans1<<endl;
            else cout<<ans2<<endl;
        }
        else{
            if(x==0)cout<<ans2<<endl;
            else cout<<ans1<<endl;
        }
    }
    return 0;
}
0