結果

問題 No.314 ケンケンパ
ユーザー furafura
提出日時 2020-04-18 00:57:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 1,000 ms
コード長 1,471 bytes
コンパイル時間 2,146 ms
コンパイル使用メモリ 195,436 KB
実行使用メモリ 15,368 KB
最終ジャッジ日時 2024-04-14 18:08:57
合計ジャッジ時間 3,218 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
15,128 KB
testcase_01 AC 6 ms
15,284 KB
testcase_02 AC 5 ms
15,264 KB
testcase_03 AC 6 ms
15,180 KB
testcase_04 AC 6 ms
15,212 KB
testcase_05 AC 6 ms
15,356 KB
testcase_06 AC 6 ms
15,232 KB
testcase_07 AC 5 ms
15,160 KB
testcase_08 AC 5 ms
15,280 KB
testcase_09 AC 5 ms
15,260 KB
testcase_10 AC 6 ms
15,332 KB
testcase_11 AC 6 ms
15,124 KB
testcase_12 AC 5 ms
15,368 KB
testcase_13 AC 6 ms
15,144 KB
testcase_14 AC 6 ms
15,128 KB
testcase_15 AC 5 ms
15,320 KB
testcase_16 AC 6 ms
15,156 KB
testcase_17 AC 5 ms
15,124 KB
testcase_18 AC 7 ms
15,268 KB
testcase_19 AC 8 ms
15,132 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 mint(-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=mint(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 y,const mint& m){ return m+y; }
mint operator*(long long y,const mint& m){ return m*y; }

int main(){
	int n; cin>>n; n--;

	static mint dp[1000000][3];
	dp[0][0]=1;
	rep(i,n){
		dp[i+1][0]=dp[i][2];
		dp[i+1][1]=dp[i][0];
		dp[i+1][2]=dp[i][0]+dp[i][1];
	}
	cout<<dp[n][0]+dp[n][1]+dp[n][2]<<'\n';

	return 0;
}
0