結果

問題 No.314 ケンケンパ
ユーザー ScottShelbyScottShelby
提出日時 2020-09-01 01:56:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 1,000 ms
コード長 1,561 bytes
コンパイル時間 1,438 ms
コンパイル使用メモリ 166,420 KB
実行使用メモリ 26,880 KB
最終ジャッジ日時 2024-04-28 11:46:44
合計ジャッジ時間 2,602 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
26,880 KB
testcase_01 AC 15 ms
26,880 KB
testcase_02 AC 16 ms
26,880 KB
testcase_03 AC 17 ms
26,880 KB
testcase_04 AC 17 ms
26,752 KB
testcase_05 AC 17 ms
26,880 KB
testcase_06 AC 17 ms
26,752 KB
testcase_07 AC 17 ms
26,752 KB
testcase_08 AC 17 ms
26,880 KB
testcase_09 AC 18 ms
26,880 KB
testcase_10 AC 17 ms
26,880 KB
testcase_11 AC 17 ms
26,880 KB
testcase_12 AC 17 ms
26,752 KB
testcase_13 AC 17 ms
26,880 KB
testcase_14 AC 17 ms
26,880 KB
testcase_15 AC 16 ms
26,880 KB
testcase_16 AC 17 ms
26,752 KB
testcase_17 AC 17 ms
26,880 KB
testcase_18 AC 19 ms
26,880 KB
testcase_19 AC 20 ms
26,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 mod
  mint 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;
}
0