結果
問題 | No.314 ケンケンパ |
ユーザー |
![]() |
提出日時 | 2020-09-01 01:56:20 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 13 ms / 1,000 ms |
コード長 | 1,561 bytes |
コンパイル時間 | 1,756 ms |
コンパイル使用メモリ | 167,176 KB |
実行使用メモリ | 27,008 KB |
最終ジャッジ日時 | 2024-11-17 03:03:50 |
合計ジャッジ時間 | 2,689 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#include<bits/stdc++.h>#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)#define chmax(x,y) x=max(x,y)#define chmin(x,y) x=min(x,y)using namespace std;typedef long long ll;typedef pair<int,int> P;const int mod = 1000000007;const int INF = 1001001001;struct mint {ll x; // typedef long long ll;mint(ll x=0):x((x%mod+mod)%mod){}mint operator-() const { return mint(-x);}mint& operator+=(const mint a) {if ((x += a.x) >= mod) x -= mod;return *this;}mint& operator-=(const mint a) {if ((x += mod-a.x) >= mod) x -= mod;return *this;}mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}mint operator+(const mint a) const { return mint(*this) += a;}mint operator-(const mint a) const { return mint(*this) -= a;}mint operator*(const mint a) const { return mint(*this) *= a;}mint pow(ll t) const {if (!t) return 1;mint a = pow(t>>1);a *= a;if (t&1) a *= *this;return a;}// for prime modmint inv() const { return pow(mod-2);}mint& operator/=(const mint a) { return *this *= a.inv();}mint operator/(const mint a) const { return mint(*this) /= a;}};istream& operator>>(istream& is, const mint& a) { return is >> a.x;}ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}mint dp[1000001][3];int main() {int n;cin >> n;dp[0][1] = 1;rep(i, n) {dp[i + 1][0] = dp[i][2] + dp[i][1];dp[i + 1][1] = dp[i][0];dp[i + 1][2] = dp[i][1];}mint ans = dp[n - 1][0] + dp[n - 1][1] + dp[n - 1][2];cout << ans << endl;}