結果
問題 |
No.1331 Moving Penguin
|
ユーザー |
|
提出日時 | 2021-01-09 22:38:58 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 196 ms / 1,500 ms |
コード長 | 2,425 bytes |
コンパイル時間 | 1,825 ms |
コンパイル使用メモリ | 173,084 KB |
実行使用メモリ | 5,760 KB |
最終ジャッジ日時 | 2024-11-07 15:08:51 |
合計ジャッジ時間 | 10,049 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 49 |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define chmin(x,y) x = min((x),(y)); #define chmax(x,y) x = max((x),(y)); using namespace std; using ll = long long ; using P = pair<int,int> ; using pll = pair<long long,long long>; const int INF = 1e9; const long long LINF = 1e17; const int MOD = 1000000007; //const int MOD = 998244353; const double PI = 3.14159265358979323846; template<int mod> struct ModInt{ long long x=0; constexpr ModInt(long long x=0):x((x%mod+mod)%mod){} constexpr ModInt operator+(const ModInt& r)const{return ModInt(*this)+=r;} constexpr ModInt operator-(const ModInt& r)const{return ModInt(*this)-=r;} constexpr ModInt operator*(const ModInt& r)const{return ModInt(*this)*=r;} constexpr ModInt operator/(const ModInt& r)const{return ModInt(*this)/=r;} constexpr ModInt& operator+=(const ModInt& r){ if((x+=r.x)>=mod) x-=mod; return *this;} constexpr ModInt& operator-=(const ModInt& r){ if((x-=r.x)<0) x+=mod; return *this;} constexpr ModInt& operator*=(const ModInt& r){ if((x*=r.x)>=mod) x%=mod; return *this;} constexpr ModInt& operator/=(const ModInt& r){ return *this*=r.inv();} ModInt inv() const { long long s=x,sx=1,sy=0,t=mod,tx=0,ty=1; while(s%t!=0){ long long temp=s/t,u=s-t*temp,ux=sx-temp*tx,uy=sy-temp*ty; s=t;sx=tx;sy=ty; t=u;tx=ux;ty=uy; } return ModInt(tx); } ModInt pow(long long n) const { ModInt a=1; ModInt b=*this; while(n>0){ if(n&1) a*=b; b*=b; n>>=1; } return a; } friend constexpr ostream& operator<<(ostream& os,const ModInt<mod>& a) {return os << a.x;} friend constexpr istream& operator>>(istream& is,ModInt<mod>& a) {return is >> a.x;} }; using mint = ModInt<MOD>; int main(){ int n; cin >> n; vector<ll> a(n); rep(i,n) cin >> a[i]; vector<mint> dp(n+5,0); dp[0] = 1; int sq = sqrt(n); vector<vector<mint>> sum(sq,vector<mint>(sq,0)); for(int i=0;i<n;i++){ for(int j=1;j<sq;j++){ dp[i] += sum[j][i%j]; } if(a[i]!=1) dp[i+1] += dp[i]; if(a[i] < sq){ sum[a[i]][i%a[i]] += dp[i]; }else{ for(int j=i+a[i];j<n;j+=a[i]){ dp[j] += dp[i]; } } } cout << dp[n-1] << endl; return 0; }