結果
問題 | No.1331 Moving Penguin |
ユーザー |
![]() |
提出日時 | 2021-01-08 23:19:45 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 813 ms / 1,500 ms |
コード長 | 1,285 bytes |
コンパイル時間 | 1,072 ms |
コンパイル使用メモリ | 98,676 KB |
実行使用メモリ | 85,632 KB |
最終ジャッジ日時 | 2024-11-07 14:57:33 |
合計ジャッジ時間 | 15,947 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 49 |
ソースコード
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <cmath> #include <map> #include <queue> #include <iomanip> #include <set> #include <tuple> #define mkp make_pair #define mkt make_tuple #define rep(i,n) for(int i = 0; i < (n); ++i) #define all(v) v.begin(),v.end() using namespace std; typedef long long ll; const ll MOD=1e9+7; template<class T> void chmin(T &a,const T &b){if(a>b) a=b;} template<class T> void chmax(T &a,const T &b){if(a<b) a=b;} void add(ll &a,ll b){ a=(a+b)%MOD; } void mul(ll &a,ll b){ a%=MOD;b%=MOD; a=a*b%MOD; } const int B=100; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N; cin>>N; vector<int> A(N); rep(i,N) cin>>A[i]; A.pop_back(); N--; vector<vector<ll>> dp(N+1,vector<ll> (B+1,0)); dp[0][0]=1; for(int i=0;i<N;i++){ ll value=0; for(int j=0;j<=B;j++) add(value,dp[i][j]); for(int j=1;j<=B;j++){ if(i+j<=N) add(dp[i+j][j],dp[i][j]); } if(A[i]<=B){ if(i+A[i]<=N) add(dp[i+A[i]][A[i]],value); }else{ int now=i; while(now+A[i]<=N){ now+=A[i]; add(dp[now][0],value); } } if(A[i]>1) add(dp[i+1][0],value); } ll ans=0; for(int j=0;j<=B;j++) add(ans,dp[N][j]); cout<<ans<<endl; return 0; }