結果
問題 | No.314 ケンケンパ |
ユーザー | Noiri |
提出日時 | 2019-09-02 03:09:22 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 13 ms / 1,000 ms |
コード長 | 3,369 bytes |
コンパイル時間 | 2,416 ms |
コンパイル使用メモリ | 165,796 KB |
実行使用メモリ | 15,176 KB |
最終ジャッジ日時 | 2023-08-20 07:24:17 |
合計ジャッジ時間 | 2,910 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 12 ms
15,004 KB |
testcase_01 | AC | 8 ms
15,016 KB |
testcase_02 | AC | 9 ms
15,176 KB |
testcase_03 | AC | 8 ms
15,028 KB |
testcase_04 | AC | 9 ms
15,052 KB |
testcase_05 | AC | 9 ms
15,144 KB |
testcase_06 | AC | 9 ms
15,176 KB |
testcase_07 | AC | 8 ms
15,024 KB |
testcase_08 | AC | 9 ms
15,080 KB |
testcase_09 | AC | 9 ms
15,072 KB |
testcase_10 | AC | 8 ms
15,080 KB |
testcase_11 | AC | 9 ms
15,156 KB |
testcase_12 | AC | 8 ms
15,048 KB |
testcase_13 | AC | 8 ms
15,024 KB |
testcase_14 | AC | 9 ms
15,052 KB |
testcase_15 | AC | 8 ms
15,084 KB |
testcase_16 | AC | 9 ms
15,068 KB |
testcase_17 | AC | 9 ms
15,124 KB |
testcase_18 | AC | 11 ms
15,084 KB |
testcase_19 | AC | 13 ms
15,084 KB |
ソースコード
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ); using namespace std; using ll = long long; template <int MOD> class ModInt { using lint = long long; public: int val; // constructor ModInt(lint v = 0) : val(v % MOD) { if (val < 0) val += MOD; }; // assignment ModInt& operator=(const ModInt& x) { if (this != &x) { this->val = x.val; } return *this; } // unary operator ModInt operator+() const { return ModInt(val); } ModInt operator-() const { return ModInt(MOD - val); } ModInt operator~() const { return *this ^ (MOD - 2); } // increment / decrement ModInt& operator++() { return *this += 1; } ModInt& operator--() { return *this -= 1; } ModInt operator++(int) { ModInt before = *this; ++(*this); return before; } ModInt operator--(int) { ModInt before = *this; --(*this); return before; } // arithmetic ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; } ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; } ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; } ModInt operator%(const ModInt& x) const { return ModInt(*this) %= x; } ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; } ModInt operator^(const ModInt& x) const { return ModInt(*this) ^= x; } // compound assignment ModInt& operator+=(const ModInt& x) { if ((val += x.val) >= MOD) val -= MOD; return *this; } ModInt& operator-=(const ModInt& x) { if ((val -= x.val) < 0) val += MOD; return *this; } ModInt& operator*=(const ModInt& x) { val = lint(val) * x.val % MOD; return *this; } ModInt& operator%=(const ModInt& x) { val %= x.val; return *this; } ModInt& operator/=(const ModInt& x) { return *this *= ~x; } ModInt& operator^=(const ModInt& x) { int n = x.val; ModInt b = *this; if (n < 0) n = -n, b = ~b; *this = 1; while (n > 0) { if (n & 1) *this *= b; n >>= 1; b *= b; } return *this; } // compare bool operator==(const ModInt& b) const { return val == b.val; } bool operator!=(const ModInt& b) const { return val != b.val; } bool operator<(const ModInt& b) const { return val < b.val; } bool operator<=(const ModInt& b) const { return val <= b.val; } bool operator>(const ModInt& b) const { return val > b.val; } bool operator>=(const ModInt& b) const { return val >= b.val; } // I/O friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; } friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept { return is >> x.val; } }; using mint = ModInt<1000000007>; mint dp[1000001][3]; int main(){ int n; cin >> n; dp[0][0] = 1; rep(i, n){ dp[i+1][0] += dp[i][2]; dp[i+1][1] += dp[i][0]; rep(j, 2) dp[i+1][2] += dp[i][j]; } mint ans = 0; rep(i, 3) ans += dp[n-1][i]; cout << ans << endl; }