結果

問題 No.314 ケンケンパ
ユーザー penguinshunyapenguinshunya
提出日時 2019-03-25 13:02:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 1,000 ms
コード長 2,641 bytes
コンパイル時間 1,032 ms
コンパイル使用メモリ 109,268 KB
実行使用メモリ 27,080 KB
最終ジャッジ日時 2024-04-16 19:47:27
合計ジャッジ時間 2,104 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
27,008 KB
testcase_01 AC 10 ms
26,880 KB
testcase_02 AC 10 ms
27,004 KB
testcase_03 AC 10 ms
27,008 KB
testcase_04 AC 10 ms
26,748 KB
testcase_05 AC 9 ms
27,004 KB
testcase_06 AC 9 ms
27,008 KB
testcase_07 AC 10 ms
26,772 KB
testcase_08 AC 9 ms
27,008 KB
testcase_09 AC 10 ms
26,856 KB
testcase_10 AC 10 ms
26,940 KB
testcase_11 AC 9 ms
27,080 KB
testcase_12 AC 9 ms
26,880 KB
testcase_13 AC 9 ms
26,748 KB
testcase_14 AC 9 ms
27,008 KB
testcase_15 AC 10 ms
26,880 KB
testcase_16 AC 10 ms
26,828 KB
testcase_17 AC 12 ms
27,004 KB
testcase_18 AC 18 ms
27,008 KB
testcase_19 AC 30 ms
26,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = long long;
using u32 = unsigned long long;
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using vi32 = vector<i32>;
using vu32 = vector<u32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf64 = vector<f64>;
using vstr = vector<string>;
using vvi32 = vector<vi32>;
using vvu32 = vector<vu32>;
using vvi64 = vector<vi64>;
using vvu64 = vector<vu64>;
using vvf64 = vector<vf64>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

template<int mod> class modint {
public:
  int x;
  modint(): x(0) {}
  modint(int a) { x = a % mod; if (x < 0) x += mod; }
  modint &operator+=(modint that) { x = (x + that.x) % mod; return *this; }
  modint &operator-=(modint that) { x = (x + mod - that.x) % mod; return *this; }
  modint &operator*=(modint that) { x = (long long) x * that.x % mod; return *this; }
  modint &operator/=(modint that) { return *this *= that.inverse(); }
  modint operator-() { return modint(-this->x); }
  friend ostream& operator<<(ostream &out, modint m) { return out << m.x; }
  modint inverse() {
    int a = x, b = mod, u = 1, v = 0;
    while (b) { int t = a / b; a -= t * b; u -= t * v; swap(a, b); swap(u, v); }
    return modint(u);
  }
#define op(o, p) modint operator o(modint that) { return modint(*this) p that; }
  op(+, +=) op(-, -=) op(*, *=) op(/, /=)
#undef op
#define op(o) bool operator o(modint that) const { return x o that.x; }
  op(==) op(!=) op(<) op(<=) op(>) op(>=)
#undef op
};

using mint = modint<1000000007>;

mint dp[1000010][3][2];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  int n; cin >> n;
  dp[1][1][0] = 1;
  reps(i, n - 1) rep(j, 3) rep(k, 2) {
    if (j >= 1) dp[i + 1][0][1] += dp[i][j][k];
    if (j == 1) dp[i + 1][2][0] += dp[i][j][k];
    if (k == 1) dp[i + 1][1][0] += dp[i][j][k];
  }
  mint ans = 0;
  rep(j, 3) rep(k, 2) {
    ans += dp[n][j][k];
  }
  cout << ans << endl;
  return 0;
}
0