結果

問題 No.1073 無限すごろく
ユーザー どららどらら
提出日時 2020-06-05 22:52:42
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,523 bytes
コンパイル時間 1,827 ms
コンパイル使用メモリ 172,692 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-22 16:48:03
合計ジャッジ時間 3,110 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

ll extgcd(ll a, ll b, ll &x, ll &y){
  ll d = a;
  if(b!=0){
    d = extgcd(b,a%b,y,x);
    y -= (a/b)*x;
  }else{
    x = 1; y = 0;
  }
  return d;
}

ll mod_inverse(ll a, ll m){
  ll x, y;
  extgcd(a, m, x, y);
  return (m+x%m)%m;
}

typedef vector<ll> vec;
typedef vector<vec> mat;
const ll MOD = 1000000007;
mat mul(mat &A, mat &B){ // A*B
  mat C(A.size(), vec(B[0].size()));
  rep(i,A.size()) rep(k,B.size()){
    rep(j,B[0].size()){
      C[i][j] = (C[i][j]+A[i][k]*B[k][j])%MOD;
    }
  }
  return C;
}
mat pow(mat A, ll n){ // A^n
  mat B(A.size(), vec(A.size()));
  rep(i,A.size()) B[i][i] = 1;
  while(n>0){
    if(n&1) B=mul(B,A);
    A=mul(A,A);
    n>>=1;
  }
  return B;
}
// 行列*ベクトル(A*v)
vector<ll> mulv(mat &A, vector<ll> v){
  vector<ll> ret = v;
  rep(i,v.size()){
    ll res = 0;
    rep(j,v.size()){ res += A[i][j]*v[j]; res = res%MOD; }
    ret[i] = res%MOD;
  }
  return ret;
}




int main(){
  ll N;
  cin >> N;

  vec a(6, 0);
  a[5] = 1;

  mat m(6, vec(6, 0));
  rep(i,6){
    m[i][5] = mod_inverse(6, MOD);
  }
  m[1][0] = 1;
  m[2][1] = 1;
  m[3][2] = 1;
  m[4][3] = 1;
  m[5][4] = 1;

  mat tmp = pow(m, N);
  vec ret = mulv(tmp, a);

  cout << ret[5] << endl;
  
  return 0;
}

0