結果
問題 | No.1258 コインゲーム |
ユーザー | 沙耶花 |
提出日時 | 2020-10-16 21:49:33 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,252 ms / 2,000 ms |
コード長 | 2,425 bytes |
コンパイル時間 | 2,491 ms |
コンパイル使用メモリ | 217,016 KB |
実行使用メモリ | 4,384 KB |
最終ジャッジ日時 | 2023-09-28 02:48:50 |
合計ジャッジ時間 | 41,508 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 235 ms
4,380 KB |
testcase_01 | AC | 294 ms
4,380 KB |
testcase_02 | AC | 106 ms
4,380 KB |
testcase_03 | AC | 978 ms
4,376 KB |
testcase_04 | AC | 1,098 ms
4,380 KB |
testcase_05 | AC | 173 ms
4,380 KB |
testcase_06 | AC | 800 ms
4,376 KB |
testcase_07 | AC | 79 ms
4,380 KB |
testcase_08 | AC | 68 ms
4,384 KB |
testcase_09 | AC | 400 ms
4,376 KB |
testcase_10 | AC | 976 ms
4,380 KB |
testcase_11 | AC | 1,074 ms
4,380 KB |
testcase_12 | AC | 780 ms
4,380 KB |
testcase_13 | AC | 241 ms
4,380 KB |
testcase_14 | AC | 77 ms
4,376 KB |
testcase_15 | AC | 947 ms
4,376 KB |
testcase_16 | AC | 184 ms
4,380 KB |
testcase_17 | AC | 1,074 ms
4,376 KB |
testcase_18 | AC | 392 ms
4,376 KB |
testcase_19 | AC | 360 ms
4,376 KB |
testcase_20 | AC | 794 ms
4,380 KB |
testcase_21 | AC | 1,012 ms
4,380 KB |
testcase_22 | AC | 699 ms
4,376 KB |
testcase_23 | AC | 515 ms
4,376 KB |
testcase_24 | AC | 192 ms
4,376 KB |
testcase_25 | AC | 493 ms
4,380 KB |
testcase_26 | AC | 419 ms
4,380 KB |
testcase_27 | AC | 980 ms
4,380 KB |
testcase_28 | AC | 251 ms
4,380 KB |
testcase_29 | AC | 270 ms
4,376 KB |
testcase_30 | AC | 1,219 ms
4,376 KB |
testcase_31 | AC | 300 ms
4,376 KB |
testcase_32 | AC | 132 ms
4,380 KB |
testcase_33 | AC | 816 ms
4,376 KB |
testcase_34 | AC | 1,013 ms
4,376 KB |
testcase_35 | AC | 350 ms
4,380 KB |
testcase_36 | AC | 990 ms
4,376 KB |
testcase_37 | AC | 382 ms
4,376 KB |
testcase_38 | AC | 933 ms
4,376 KB |
testcase_39 | AC | 257 ms
4,380 KB |
testcase_40 | AC | 1,251 ms
4,380 KB |
testcase_41 | AC | 1,242 ms
4,384 KB |
testcase_42 | AC | 1,243 ms
4,380 KB |
testcase_43 | AC | 1,240 ms
4,376 KB |
testcase_44 | AC | 1,251 ms
4,376 KB |
testcase_45 | AC | 1,252 ms
4,380 KB |
testcase_46 | AC | 1,243 ms
4,380 KB |
testcase_47 | AC | 1,249 ms
4,376 KB |
testcase_48 | AC | 1,248 ms
4,376 KB |
testcase_49 | AC | 1,248 ms
4,380 KB |
ソースコード
#include <stdio.h> #include <bits/stdc++.h> #include <atcoder/modint> using namespace atcoder; using mint = modint1000000007; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000001 template <typename T,typename F0,typename F1> struct matrix{ F0 func0; F1 func1; vector<vector<T>> value; int height,width; T init_value0,init_value1; matrix(vector<vector<T>> X,F0 f0,F1 f1,T iv0,T iv1):func0(f0),func1(f1){ height = X.size(); width = X[0].size(); value = X; init_value0 = iv0,init_value1 = iv1; } matrix(int h,int w,F0 f0,F1 f1,T iv0,T iv1):func0(f0),func1(f1){ vector<vector<T>> d(h,vector<T>(w,iv0)); height = h,width = w; value = d; init_value0 = iv0,init_value1 = iv1; } void set_1(){ for(int i=0;i<height;i++){ for(int j=0;j<width;j++){ if(i==j)value[i][j] = init_value1; else value[i][j]=init_value0; } } } void show(){ for(int i=0;i<height;i++){ for(int j=0;j<width;j++){ if(j!=0)cout<<' '; cout<<value[i][j]; } cout<<endl; } } matrix &operator=(const matrix &another){ value = another.value; height = another.height; width = another.width; return *this; } matrix &operator*=(const matrix &another){ matrix<T,decltype(func0),decltype(func1)> R(height,another.width,func0,func1,init_value0,init_value1); for(int i=0;i<R.value.size();i++){ for(int j=0;j<R.value[i].size();j++){ R.value[i][j]=init_value0; for(int k=0;k<width;k++){ R.value[i][j] = func0(R.value[i][j],func1(value[i][k],another.value[k][j])); } } } value = R.value; return (*this); } matrix operator*(const matrix &another)const{ return (matrix(*this)*=another); } matrix beki(long long cnt){ matrix<T,decltype(func0),decltype(func1)> R(height,width,func0,func1,init_value0,init_value1); R.set_1(); auto temp = *this; while(cnt!=0LL){ if(cnt%2==1){ R *= temp; } temp *= temp; cnt/=2; } return R; } }; int main(){ int t; cin>>t; auto f0 = [](mint a,mint b){ return a+b; }; auto f1 = [](mint a,mint b){ return a*b; }; rep(_,t){ int N,M,X; cin>>N>>M>>X; vector<vector<mint>> temp = {{1,M},{M,1}}; matrix<mint,decltype(f0),decltype(f1)> A(temp,f0,f1,0,1); A = A.beki(N); temp = {{1,0}}; matrix<mint,decltype(f0),decltype(f1)> B(temp,f0,f1,0,1); B *= A; cout<<B.value[0][X].val()<<endl; } return 0; }