結果

問題 No.1704 Many Bus Stops (easy)
ユーザー asaringoasaringo
提出日時 2021-10-09 02:34:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 149 ms / 2,000 ms
コード長 1,545 bytes
コンパイル時間 1,768 ms
コンパイル使用メモリ 174,848 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-30 18:27:22
合計ジャッジ時間 7,696 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std ;
typedef long long ll ;
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define rrep(i,a,b) for(int i = a ; i < b ; i++)

const int mod = 1000000007 ;
int n , t ;

ll powmod(ll x , ll n){
    ll res = 1 ;
    while(n > 0){
        if(n & 1) (res *= x) %= mod ;
        (x *= x) %= mod ;
        n >>= 1 ;
    }
    return res ;
}

vector<vector<ll>> A(6,vector<ll>(6)) ;

struct MATRIX{
    // A * B
    vector<vector<ll>> calculation(vector<vector<ll>> X , vector<vector<ll>> Y){
        int x = X.size() , y = Y[0].size() , n = Y.size() ;
        vector<vector<ll>> res(x,vector<ll>(y)) ;
        rep(i,x) rep(j,y) rep(k,n) {
            (res[i][j] += X[i][k] * Y[k][j]) %= mod ;
        }
        return res ;
    }

    vector<vector<ll>> dynamic(vector<vector<ll>> A , ll k){
        int n = A.size() ;
        vector<vector<ll>> res(n,vector<ll>(1,0)) ;
        res[0][0] = 1 ;
        while(k > 0){
            if(k & 1) res = calculation(A,res) ;
            A = calculation(A,A) ;
            k >>= 1 ;
        }
        return res ;
    }

    ll slv(vector<vector<ll>> res){
        int n = res.size() ;
        ll ans = 0 ;
        rep(i,n) (ans += res[i][0]) %= mod ;
        return ans ;
    }
};

int main(){
    cin >> t ;
    rep(i,3) A[i*2][i*2] = powmod(3,mod-2) ;
    rep(i,3) A[i*2][i*2+1] = 1 ;
    rep(i,3) rep(j,2) A[i*2+1][(i*2+2*(j+1))%6] = powmod(3,mod-2) % mod ;
    rep(i,t){
        cin >> n ;
        MATRIX mtx ;
        cout << mtx.dynamic(A,n)[0][0] << endl ;
    }
}
0