結果
問題 | No.1847 Good Sequence |
ユーザー | 沙耶花 |
提出日時 | 2022-02-18 22:18:27 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 62 ms / 3,000 ms |
コード長 | 2,770 bytes |
コンパイル時間 | 4,880 ms |
コンパイル使用メモリ | 281,500 KB |
実行使用メモリ | 4,384 KB |
最終ジャッジ日時 | 2023-09-11 19:23:47 |
合計ジャッジ時間 | 6,898 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 2 ms
4,376 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,380 KB |
testcase_07 | AC | 2 ms
4,376 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,376 KB |
testcase_12 | AC | 1 ms
4,376 KB |
testcase_13 | AC | 2 ms
4,380 KB |
testcase_14 | AC | 2 ms
4,376 KB |
testcase_15 | AC | 2 ms
4,376 KB |
testcase_16 | AC | 1 ms
4,376 KB |
testcase_17 | AC | 2 ms
4,384 KB |
testcase_18 | AC | 2 ms
4,376 KB |
testcase_19 | AC | 2 ms
4,376 KB |
testcase_20 | AC | 2 ms
4,380 KB |
testcase_21 | AC | 30 ms
4,376 KB |
testcase_22 | AC | 6 ms
4,380 KB |
testcase_23 | AC | 1 ms
4,380 KB |
testcase_24 | AC | 2 ms
4,376 KB |
testcase_25 | AC | 11 ms
4,376 KB |
testcase_26 | AC | 2 ms
4,376 KB |
testcase_27 | AC | 3 ms
4,380 KB |
testcase_28 | AC | 8 ms
4,380 KB |
testcase_29 | AC | 1 ms
4,376 KB |
testcase_30 | AC | 3 ms
4,376 KB |
testcase_31 | AC | 14 ms
4,380 KB |
testcase_32 | AC | 9 ms
4,376 KB |
testcase_33 | AC | 32 ms
4,376 KB |
testcase_34 | AC | 2 ms
4,380 KB |
testcase_35 | AC | 2 ms
4,380 KB |
testcase_36 | AC | 28 ms
4,376 KB |
testcase_37 | AC | 21 ms
4,380 KB |
testcase_38 | AC | 2 ms
4,376 KB |
testcase_39 | AC | 2 ms
4,376 KB |
testcase_40 | AC | 62 ms
4,376 KB |
ソースコード
#include <stdio.h> #include <bits/stdc++.h> #include <atcoder/all> using namespace atcoder; using mint = modint1000000007; using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) #define Inf 1000000001 template <class S, S (*op0)(S, S), S (*e0)(), S (*op1)(S, S), S (*e1)() > struct matrix{ vector<vector<S>> v; int _h,_w; matrix(vector<vector<S>> X){ v = X; _h = X.size(); _w = 0; if(X.size()>0)_w = X[0].size(); } matrix(int h,int w){ v.resize(h,vector<S>(w,e0())); _h = h; _w = w; } void add_element(int from,int to,S x){ v[to][from] = op0(v[to][from],x); } matrix e(){ assert(_h==_w); matrix<S,op0,e0,op1,e1> ret(_h,_w); for(int i=0;i<_h;i++){ for(int j=0;j<_w;j++){ if(i==j)ret.v[i][j] = e1(); else ret.v[i][j] = e0(); } } return ret; } matrix &operator*=(const matrix &another){ matrix<S,op0,e0,op1,e1> ret(_h,another._w); for(int i=0;i<_h;i++){ for(int j=0;j<another._w;j++){ ret.v[i][j] = e0(); for(int k=0;k<_w;k++){ ret.v[i][j] = op0(ret.v[i][j],op1(v[i][k],another.v[k][j])); } } } v = ret.v; return (*this); } matrix operator*(const matrix &another)const{ return (matrix(*this)*=another); } matrix pow(long long cnt){ matrix<S,op0,e0,op1,e1> ret = e(); auto temp = *this; while(cnt!=0LL){ if((cnt&1)==1){ ret *= temp; } temp *= temp; cnt>>=1; } return ret; } }; mint op0(mint a,mint b){ return a+b; } mint e0(){ return 0; } mint op1(mint a,mint b){ return a*b; } mint e1(){ return 1; } int main(){ long long L,N,m; cin>>L>>N>>m; vector<int> K(m); rep(i,m)cin>>K[i]; map<pair<int,int> ,int> mp; int t= 0; rep(i,m){ for(int j=1;j<=K[i]+1;j++){ mp[make_pair(K[i],j)] = t; t++; } } //cout<<'a'<<endl; int start = t; t++; int goal = t; t++; matrix<mint,op0,e0,op1,e1> M(t,t); //cout<<'a'<<endl; for(int i=1;i<=N;i++){ if(mp.count(make_pair(i,1))){ M.add_element(start,mp[make_pair(i,1)],1); } else{ M.add_element(start,start,1); } } M.add_element(goal,goal,N); //cout<<'a'<<endl; rep(i,m){ for(int j=1;j<=K[i]+1;j++){ for(int k=1;k<=N;k++){ int from = mp[make_pair(K[i],j)]; int to; if(K[i]==k){ to = mp[make_pair(K[i],min(j+1,K[i]+1))]; } else{ if(j==K[i])to = goal; else{ if(mp.count(make_pair(k,1)))to = mp[make_pair(k,1)]; else to = start; } } M.add_element(from,to,1); } } } // cout<<'a'<<endl; M = M.pow(L); matrix<mint,op0,e0,op1,e1> temp(t,1); temp.v[start][0] = 1; temp = M * temp; mint ans = 0; rep(i,m){ ans += temp.v[mp[make_pair(K[i],K[i])]][0]; } ans += temp.v[goal][0]; cout<<ans.val()<<endl; return 0; }