結果

問題 No.1704 Many Bus Stops (easy)
ユーザー harurunharurun
提出日時 2021-09-11 01:22:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 175 ms / 2,000 ms
コード長 1,617 bytes
コンパイル時間 945 ms
コンパイル使用メモリ 81,132 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-30 09:29:42
合計ジャッジ時間 7,436 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 168 ms
4,376 KB
testcase_02 AC 60 ms
4,376 KB
testcase_03 AC 61 ms
4,376 KB
testcase_04 AC 62 ms
4,380 KB
testcase_05 AC 62 ms
4,380 KB
testcase_06 AC 60 ms
4,376 KB
testcase_07 AC 61 ms
4,380 KB
testcase_08 AC 60 ms
4,380 KB
testcase_09 AC 61 ms
4,376 KB
testcase_10 AC 62 ms
4,376 KB
testcase_11 AC 61 ms
4,380 KB
testcase_12 AC 60 ms
4,380 KB
testcase_13 AC 61 ms
4,376 KB
testcase_14 AC 60 ms
4,376 KB
testcase_15 AC 62 ms
4,376 KB
testcase_16 AC 61 ms
4,380 KB
testcase_17 AC 60 ms
4,376 KB
testcase_18 AC 61 ms
4,376 KB
testcase_19 AC 64 ms
4,376 KB
testcase_20 AC 62 ms
4,384 KB
testcase_21 AC 60 ms
4,376 KB
testcase_22 AC 167 ms
4,376 KB
testcase_23 AC 168 ms
4,380 KB
testcase_24 AC 174 ms
4,380 KB
testcase_25 AC 172 ms
4,380 KB
testcase_26 AC 175 ms
4,380 KB
testcase_27 AC 172 ms
4,380 KB
testcase_28 AC 170 ms
4,376 KB
testcase_29 AC 170 ms
4,380 KB
testcase_30 AC 165 ms
4,380 KB
testcase_31 AC 172 ms
4,380 KB
testcase_32 AC 175 ms
4,380 KB
testcase_33 AC 174 ms
4,376 KB
testcase_34 AC 171 ms
4,380 KB
testcase_35 AC 166 ms
4,380 KB
testcase_36 AC 170 ms
4,380 KB
testcase_37 AC 166 ms
4,376 KB
testcase_38 AC 164 ms
4,376 KB
testcase_39 AC 168 ms
4,380 KB
testcase_40 AC 172 ms
4,376 KB
testcase_41 AC 166 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

const long long mod=1000000007;
const vector<vector<long long>>a{
  {1,0,0,0,1,1},
  {0,1,0,1,0,1},
  {0,0,1,1,1,0},
  {3,0,0,0,0,0},
  {0,3,0,0,0,0},
  {0,0,3,0,0,0}
};
const vector<vector<long long>> b={
    {1},{0},{0},{3},{0},{0}
};

vector<vector<long long>> matrix_mul(const vector<vector<long long>>& A,const vector<vector<long long>>&B){
  vector<vector<long long>>C(A.size(),vector<long long>(B.at(0).size(),0));
  for(int i=0;i<A.size();i++){
    for(int k=0;k<B.size();k++){
      for(int j=0;j<B.at(0).size();j++){
        C.at(i).at(j)=(C.at(i).at(j)+A.at(i).at(k)*B.at(k).at(j))%mod;
      }
    }
  }
  return C;
}

vector<vector<long long>> matrix_exp(vector<vector<long long>> X,long long n){
  vector<vector<long long>>Y(X.size(),vector<long long>(X.size(),0));
  for(int i=0;i<X.size();i++){
    Y.at(i).at(i)=1;
  }
  while(n>0){
    if(n&1){
      Y=matrix_mul(Y,X);
    }
    X=matrix_mul(X,X);
    n>>=1;
  }
  return Y;
}

long long calculate_nth(long long n,vector<vector<long long>> A){
  A=matrix_exp(A,n);
  vector<vector<long long>> res;
  res=matrix_mul(A,b);
  return res.at(3).at(0);
}

long long mod_pow(long long x,long long n,long long m){
  long long res=1;
  while(n>0){
    if(n&1){
      res=res*x%m;
    }
    x=x*x%m;
    n>>=1;
  }
  return res;
}

void solve(){
  long long N;
  cin>>N;
  long long ans,c,An;
  ans=calculate_nth(N,a);
  c=mod_pow(mod_pow(3,mod-2,mod),N+1,mod);
  An=ans*c%mod;
  cout<<An<<endl;
  return;
}

int main(){
  int T;
  cin>>T;
  for(int i=0;i<T;i++){
    solve();
  }
  return 0;
}



0