結果

問題 No.1331 Moving Penguin
ユーザー furafura
提出日時 2021-01-09 19:25:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 378 ms / 1,500 ms
コード長 1,834 bytes
コンパイル時間 2,324 ms
コンパイル使用メモリ 204,908 KB
実行使用メモリ 82,804 KB
最終ジャッジ日時 2023-08-07 11:15:33
合計ジャッジ時間 18,000 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,944 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 323 ms
82,804 KB
testcase_05 AC 375 ms
82,516 KB
testcase_06 AC 378 ms
82,580 KB
testcase_07 AC 369 ms
82,656 KB
testcase_08 AC 321 ms
82,516 KB
testcase_09 AC 321 ms
82,512 KB
testcase_10 AC 326 ms
82,520 KB
testcase_11 AC 319 ms
82,460 KB
testcase_12 AC 326 ms
82,556 KB
testcase_13 AC 327 ms
82,468 KB
testcase_14 AC 322 ms
82,472 KB
testcase_15 AC 325 ms
82,508 KB
testcase_16 AC 333 ms
82,508 KB
testcase_17 AC 328 ms
82,576 KB
testcase_18 AC 317 ms
82,632 KB
testcase_19 AC 324 ms
82,464 KB
testcase_20 AC 312 ms
82,636 KB
testcase_21 AC 312 ms
82,556 KB
testcase_22 AC 319 ms
82,632 KB
testcase_23 AC 321 ms
82,652 KB
testcase_24 AC 322 ms
82,784 KB
testcase_25 AC 327 ms
82,468 KB
testcase_26 AC 335 ms
82,556 KB
testcase_27 AC 336 ms
82,572 KB
testcase_28 AC 338 ms
82,516 KB
testcase_29 AC 319 ms
82,568 KB
testcase_30 AC 92 ms
30,244 KB
testcase_31 AC 168 ms
48,468 KB
testcase_32 AC 72 ms
26,384 KB
testcase_33 AC 148 ms
38,844 KB
testcase_34 AC 196 ms
56,768 KB
testcase_35 AC 352 ms
82,464 KB
testcase_36 AC 358 ms
82,632 KB
testcase_37 AC 355 ms
82,512 KB
testcase_38 AC 97 ms
31,564 KB
testcase_39 AC 257 ms
80,404 KB
testcase_40 AC 129 ms
42,980 KB
testcase_41 AC 327 ms
82,588 KB
testcase_42 AC 359 ms
82,528 KB
testcase_43 AC 362 ms
82,600 KB
testcase_44 AC 356 ms
82,632 KB
testcase_45 AC 359 ms
82,612 KB
testcase_46 AC 359 ms
82,588 KB
testcase_47 AC 363 ms
82,528 KB
testcase_48 AC 318 ms
82,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

class mint{
	static const int MOD=1e9+7;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }
	mint operator-()const{ return -x; }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=t; return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint operator+(long long x,const mint& m){ return mint(x)+m; }
mint operator-(long long x,const mint& m){ return mint(x)-m; }
mint operator*(long long x,const mint& m){ return mint(x)*m; }
mint operator/(long long x,const mint& m){ return mint(x)/m; }

int main(){
	int n; scanf("%d",&n);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	vector dp(n,mint(0));
	vector cum(200,vector(n,mint(0)));
	dp[0]=1;
	rep(i,n){
		rep(t,200){
			dp[i]+=cum[t][i];
		}

		if(i+1<n && a[i]!=1){
			dp[i+1]+=dp[i];
		}
		if(a[i]<200){
			cum[a[i]][i]+=dp[i];
		}
		else{
			for(int j=i+a[i];j<n;j+=a[i]){
				dp[j]+=dp[i];
			}
		}
		rep(t,200) if(i+t<n) {
			cum[t][i+t]+=cum[t][i];
		}
	}
	cout<<dp[n-1]<<'\n';

	return 0;
}
0