結果

問題 No.1331 Moving Penguin
ユーザー kotatsugamekotatsugame
提出日時 2021-01-08 21:38:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 142 ms / 1,500 ms
コード長 2,593 bytes
コンパイル時間 580 ms
コンパイル使用メモリ 64,748 KB
実行使用メモリ 5,424 KB
最終ジャッジ日時 2023-08-07 10:42:59
合計ジャッジ時間 7,475 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 125 ms
5,424 KB
testcase_05 AC 116 ms
4,844 KB
testcase_06 AC 115 ms
4,676 KB
testcase_07 AC 116 ms
4,540 KB
testcase_08 AC 111 ms
4,384 KB
testcase_09 AC 111 ms
4,380 KB
testcase_10 AC 111 ms
4,380 KB
testcase_11 AC 111 ms
4,376 KB
testcase_12 AC 111 ms
4,380 KB
testcase_13 AC 110 ms
4,376 KB
testcase_14 AC 111 ms
4,380 KB
testcase_15 AC 111 ms
4,384 KB
testcase_16 AC 112 ms
4,380 KB
testcase_17 AC 111 ms
4,380 KB
testcase_18 AC 111 ms
4,380 KB
testcase_19 AC 111 ms
4,376 KB
testcase_20 AC 110 ms
4,388 KB
testcase_21 AC 111 ms
4,380 KB
testcase_22 AC 111 ms
4,380 KB
testcase_23 AC 111 ms
4,376 KB
testcase_24 AC 111 ms
4,388 KB
testcase_25 AC 111 ms
4,400 KB
testcase_26 AC 127 ms
4,772 KB
testcase_27 AC 126 ms
4,820 KB
testcase_28 AC 126 ms
4,972 KB
testcase_29 AC 125 ms
4,380 KB
testcase_30 AC 44 ms
4,380 KB
testcase_31 AC 73 ms
4,520 KB
testcase_32 AC 39 ms
4,380 KB
testcase_33 AC 57 ms
4,488 KB
testcase_34 AC 86 ms
4,552 KB
testcase_35 AC 138 ms
4,556 KB
testcase_36 AC 138 ms
4,380 KB
testcase_37 AC 137 ms
4,572 KB
testcase_38 AC 46 ms
4,380 KB
testcase_39 AC 122 ms
4,720 KB
testcase_40 AC 64 ms
4,676 KB
testcase_41 AC 134 ms
5,244 KB
testcase_42 AC 141 ms
4,376 KB
testcase_43 AC 142 ms
4,380 KB
testcase_44 AC 141 ms
4,380 KB
testcase_45 AC 141 ms
4,380 KB
testcase_46 AC 140 ms
4,376 KB
testcase_47 AC 140 ms
4,380 KB
testcase_48 AC 111 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
a.cpp:9:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]

ソースコード

diff #

#line 1 "a.cpp"
#include<iostream>
using namespace std;
#line 3 "/home/kotatsugame/library/math/modint.cpp"
#include<utility>
template<int m>
struct modint{
	unsigned int x;
	constexpr modint()noexcept:x(){}
	template<typename T>
	constexpr modint(T x_)noexcept:x((x_%=m)<0?x_+m:x_){}
	constexpr unsigned int val()const noexcept{return x;}
	constexpr modint&operator++()noexcept{if(++x==m)x=0;return*this;}
	constexpr modint&operator--()noexcept{if(x==0)x=m;--x;return*this;}
	constexpr modint operator++(int)noexcept{modint res=*this;++*this;return res;}
	constexpr modint operator--(int)noexcept{modint res=*this;--*this;return res;}
	constexpr modint&operator+=(const modint&a)noexcept{x+=a.x;if(x>=m)x-=m;return*this;}
	constexpr modint&operator-=(const modint&a)noexcept{if(x<a.x)x+=m;x-=a.x;return*this;}
	constexpr modint&operator*=(const modint&a)noexcept{x=(unsigned long long)x*a.x%m;return*this;}
	constexpr modint&operator/=(const modint&a)noexcept{return*this*=a.inv();}
	constexpr modint operator+()const noexcept{return*this;}
	constexpr modint operator-()const noexcept{return modint()-*this;}
	constexpr modint pow(long long n)const noexcept
	{
		if(n<0)return pow(-n).inv();
		modint x=*this,r=1;
		for(;n;x*=x,n>>=1)if(n&1)r*=x;
		return r;
	}
	constexpr modint inv()const noexcept
	{
		int s=x,t=m,x=1,u=0;
		while(t)
		{
			int k=s/t;
			s-=k*t;
			swap(s,t);
			x-=k*u;
			swap(x,u);
		}
		return modint(x);
	}
	friend constexpr modint operator+(const modint&a,const modint&b){return modint(a)+=b;}
	friend constexpr modint operator-(const modint&a,const modint&b){return modint(a)-=b;}
	friend constexpr modint operator*(const modint&a,const modint&b){return modint(a)*=b;}
	friend constexpr modint operator/(const modint&a,const modint&b){return modint(a)/=b;}
	friend constexpr bool operator==(const modint&a,const modint&b){return a.x==b.x;}
	friend constexpr bool operator!=(const modint&a,const modint&b){return a.x!=b.x;}
	friend ostream&operator<<(ostream&os,const modint&a){return os<<a.x;}
	friend istream&operator>>(istream&is,modint&a){long long v;is>>v;a=modint(v);return is;}
};
#line 4 "a.cpp"
using mint=modint<(int)1e9+7>;
const int B=250;
mint add[B][1<<17];
mint dp[1<<17];
int N,A[1<<17];
main()
{
	cin>>N;
	for(int i=1;i<=N;i++)cin>>A[i];
	dp[1]=1;
	for(int i=1;i<=N;i++)
	{
		mint now=dp[i];
		for(int j=1;j<B;j++)now+=add[j][i%j];
		dp[i]=now;
		dp[i+1]+=now;
		if(i>1&&A[i-1]==1)add[1][0]+=dp[i-1];
		if(A[i]<B)
		{
			if(A[i]>1)add[A[i]][i%A[i]]+=now;
		}
		else
		{
			for(int k=1;i+A[i]*k<=N;k++)dp[i+A[i]*k]+=now;
		}
	}
	cout<<dp[N]<<endl;
}
0