結果

問題 No.840 ほむほむほむら
ユーザー tempura_pptempura_pp
提出日時 2019-03-26 01:25:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,535 bytes
コンパイル時間 1,166 ms
コンパイル使用メモリ 102,972 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 11:58:30
合計ジャッジ時間 2,673 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const int mod=1e9+7 ;

template<typename T>
struct Matrix{
    int h,w;
    vector<T> a;
    Matrix(int n_=0):h(n_),w(n_),a(n_*n_){}
    Matrix(int n_, int m_):h(n_),w(m_),a(n_*m_){}
    Matrix(int n_, int m_, vector<T> a_):h(n_),w(m_),a(a_){}
    T& get(int r,int c){return a[r*w+c];}
    T get(int r,int c)const{return a[r*w+c];}

    Matrix& operator+=(const Matrix& m) {
        assert(h == m.h && w == m.w);
        for (int i = 0; i < w*h; ++i)a[i] += m.a[i];
    }
    Matrix& operator-=(const Matrix& m) {
        assert(h == m.h && w == m.w);
        for (int i = 0; i < w*h; ++i)a[i] -= m.a[i];
    }
    Matrix& operator*=(const Matrix& m) {
        assert(w == m.h);
        Matrix ret(h, m.w);
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < m.w; ++j) {
                for (int k = 0; k < w; ++k) {
                    ret.a[i * m.w + j] += a[i * w + k] * m.a[k * m.w + j]%mod;
                }
            ret.a[i * m.w + j] %= mod;
            }
        }
        return (*this) = ret;
    }
    Matrix operator+(const Matrix& m) const { return Matrix(*this) += m; }
    Matrix operator-(const Matrix& m) const { return Matrix(*this) -= m; }
    Matrix operator*(const Matrix& m) const { return Matrix(*this) *= m; }
};
template<typename T>
Matrix<T> unit(int n){
    Matrix<T> ret(n);
    rep(i,n)ret.get(i,i)=1;
    return ret;
}
template<typename T>
Matrix<T> matpow(Matrix<T> a,ll n){
    assert(a.h==a.w);
    Matrix<T> ret=unit<T>(a.h);
    while(n){
        if(n&1)ret*=a;
        a*=a;
        n>>=1;
    }
    return ret;
}
int main(){
    ll n,m;
    cin>>n>>m;
    Matrix<ll> a(m*m*m);
    rep(i,m)rep(j,m)rep(k,m){
        int cur=i*m*m+j*m+k;
        int nxt1=i*m*m+j*m+(k+1)%m;
        int nxt2=i*m*m+(j+k)%m*m+k;
        int nxt3=(i+j)%m*m*m+j*m+k;
        a.get(nxt1,cur)+=1;
        a.get(nxt2,cur)+=1;
        a.get(nxt3,cur)+=1;
    }
    auto ret=matpow(a,n);
    ll ans=0;

    rep(i,m*m){
        ans+=ret.get(0,i);
    }
    cout<<ans%mod<<endl;
    return 0;
}
0