結果

問題 No.533 Mysterious Stairs
ユーザー heabiheabi
提出日時 2020-11-22 17:47:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 79 ms / 5,000 ms
コード長 1,966 bytes
コンパイル時間 1,572 ms
コンパイル使用メモリ 169,092 KB
実行使用メモリ 57,692 KB
最終ジャッジ日時 2023-09-30 22:59:54
合計ジャッジ時間 3,432 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 10 ms
9,088 KB
testcase_21 AC 12 ms
9,892 KB
testcase_22 AC 32 ms
23,868 KB
testcase_23 AC 78 ms
56,896 KB
testcase_24 AC 79 ms
57,692 KB
testcase_25 AC 12 ms
9,028 KB
testcase_26 AC 68 ms
50,204 KB
testcase_27 AC 21 ms
16,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
#define vvvvll vector<vector<vector<vector<ll>>>>
#define vvvll vector<vector<vector<ll>>>
#define vvll vector<vector<ll>>
#define vll vector<ll>
#define pqll priority_queue<ll>
#define pqllg priority_queue<ll, vector<ll>, greater<ll>>

constexpr ll INF = (1ll << 60);
constexpr ll mod = 1000000007;
// constexpr ll mod = 998244353;
// constexpr ll mod = 67280421310721;
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

void pt_vvll(vvll v) {
    ll vs = v.size(), vs0 = v[0].size();
    rep(i, vs) {
        rep(j, vs0) {
            cout << v[i][j];

            if (j != vs0 - 1)
                cout << " ";
            else
                cout << "\n";
        }
    }
}
void pt_vll(vll v) {
    ll vs = v.size();
    rep(i, vs) {
        cout << v[i];
        if (i == vs - 1)
            cout << "\n";
        else
            cout << " ";
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll N;
    cin >> N;
    vvll dp(N + 1, vll(3));
    dp[1][0] = 1;
    if (2 < N + 1) dp[2][1] = 1;
    if (3 < N + 1) dp[3][2] = 1;
    rep(i, N) {
        if (i + 1 <= N) {
            dp[i + 1][0] += dp[i][1] + dp[i][2];
            dp[i + 1][0] %= mod;
        }
        if (i + 2 <= N) {
            dp[i + 2][1] += dp[i][0] + dp[i][2];
            dp[i + 2][1] %= mod;
        }
        if (i + 3 <= N) {
            dp[i + 3][2] += dp[i][0] + dp[i][1];
            dp[i + 3][2] %= mod;
        }
    }

    cout << (dp[N][0] + dp[N][1] + dp[N][2]) % mod << "\n";
    return 0;
}
0