結果

問題 No.1704 Many Bus Stops (easy)
ユーザー abc3abc3
提出日時 2021-10-11 23:03:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 1,919 bytes
コンパイル時間 2,808 ms
コンパイル使用メモリ 207,828 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 09:33:30
合計ジャッジ時間 7,181 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

    #include <bits/stdc++.h>
    using namespace std;
    #include <math.h>
    #include <iomanip>
    #include <cstdint>
    #include <string>
    #include <sstream>
    template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
    template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
    #define rep(i,n) for (int i = 0; i < (n); ++i)
    typedef long long ll;
    typedef long double ld;
    typedef unsigned long long ull;
    using P=pair<ll,ll>;
    const ll INF=1e18;
    const int mod=1e9+7;
    
    typedef vector<ll> vec;
    typedef vector<vec> mat;

    mat mul(mat &A,mat &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){
        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;
    }

    ll mod_pow(ll x,ll n,ll m){
        if(n==0){return 1;}
        ll res=mod_pow(x*x%m,n/2,m);
        if(n&1){res=res*x%m;}
        return res;
    }
    mat 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},
    };
    mat b={ {1},{0},{0},{3},{0},{0} };

    void solve(){
        ll n;
        cin>>n;
        auto x=pow(a,n);
        auto t=mul(x,b);
        ll div=mod_pow( mod_pow(3,mod-2,mod) ,n+1,mod);
        ll ans=t[3][0]*div%mod;
        cout<<ans<<endl;
    } 
    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        
        int t;
        cin>>t;
        rep(i,t){
            solve();  
        }

        return 0;
    }
0