結果

問題 No.569 3 x N グリッドのパスの数
ユーザー latte0119latte0119
提出日時 2017-09-08 23:50:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 2,237 bytes
コンパイル時間 1,250 ms
コンパイル使用メモリ 152,376 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-07 08:38:57
合計ジャッジ時間 3,227 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 3 ms
4,380 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 3 ms
4,376 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 2 ms
4,376 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 2 ms
4,380 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 2 ms
4,376 KB
testcase_52 AC 2 ms
4,376 KB
testcase_53 AC 2 ms
4,380 KB
testcase_54 AC 2 ms
4,380 KB
testcase_55 AC 2 ms
4,380 KB
testcase_56 AC 3 ms
4,376 KB
testcase_57 AC 2 ms
4,380 KB
testcase_58 AC 2 ms
4,376 KB
testcase_59 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int mod=1000000007;
typedef vector<int>vec;
typedef vector<vec>mat;


int mod_pow(int n,int m){
    int ret=1;
    while(m){
        if(m&1)ret=ret*n%mod;
        n=n*n%mod;
        m>>=1;
    }
    return ret;
}

mat mul(const mat &A,const mat &B){
    mat C(A.size(),vec(B[0].size()));
    for(int i=0;i<A.size();i++){
        for(int j=0;j<B[0].size();j++){
            for(int k=0;k<A[0].size();k++){
                C[i][j]=(C[i][j]+A[i][k]*B[k][j])%mod;
            }
        }
    }
    return C;
}

mat mat_pow(mat A,int m){
    mat B(A.size(),vec(A.size()));
    for(int i=0;i<A.size();i++)B[i][i]=1;
    while(m){
        if(m&1)B=mul(B,A);
        A=mul(A,A);
        m>>=1;
    }
    return B;
}

signed main(){
    mat A(12,vec(12));

    A[0][0]++;
    A[1][0]++;
    A[2][0]++;
    A[3][0]++;
    A[4][0]++;
    A[5][0]++;
    A[6][0]++;
    A[8][0]++;

    A[1][1]++;
    A[2][1]++;
    A[6][1]++;
    A[8][1]++;

    A[1][2]++;
    A[2][2]++;
    A[3][2]++;
    A[6][2]++;
    A[8][2]++;

    A[2][3]++;
    A[3][3]++;
    A[5][3]++;
    A[8][3]++;

    A[0][4]++;
    A[3][4]++;
    A[4][4]++;
    A[5][4]++;
    A[6][4]++;
    A[8][4]++;

    A[3][5]++;
    A[5][5]++;
    A[8][5]++;

    A[0][6]++;
    A[4][6]++;
    A[6][6]++;
    A[7][6]++;
    A[8][6]++;
    A[11][6]++;

    A[0][7]++;
    A[7][7]++;
    A[11][7]++;

    A[0][8]++;
    A[4][8]++;
    A[6][8]++;
    A[7][8]++;
    A[8][8]++;
    A[9][8]++;
    A[10][8]++;
    A[11][8]++;

    A[0][9]++;
    A[4][9]++;
    A[9][9]++;
    A[10][9]++;

    A[0][10]++;
    A[4][10]++;
    A[9][10]++;
    A[10][10]++;
    A[11][10]++;

    A[0][11]++;
    A[7][11]++;
    A[10][11]++;
    A[11][11]++;

    mat X(12,vec(1));
    X[0][0]=1;
    int N;cin>>N;
    X=mul(mat_pow(A,N+1),X);

    cout<<X[8][0]<<endl;
    return 0;
}
0