結果

問題 No.533 Mysterious Stairs
ユーザー Konton7Konton7
提出日時 2020-03-20 13:31:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 96 ms / 5,000 ms
コード長 2,459 bytes
コンパイル時間 2,056 ms
コンパイル使用メモリ 205,228 KB
実行使用メモリ 73,620 KB
最終ジャッジ日時 2023-08-20 21:38:33
合計ジャッジ時間 5,700 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
73,388 KB
testcase_01 AC 87 ms
73,208 KB
testcase_02 AC 87 ms
73,328 KB
testcase_03 AC 88 ms
73,348 KB
testcase_04 AC 88 ms
73,536 KB
testcase_05 AC 88 ms
73,492 KB
testcase_06 AC 87 ms
73,264 KB
testcase_07 AC 88 ms
73,284 KB
testcase_08 AC 87 ms
73,220 KB
testcase_09 AC 87 ms
73,388 KB
testcase_10 AC 89 ms
73,276 KB
testcase_11 AC 88 ms
73,388 KB
testcase_12 AC 87 ms
73,280 KB
testcase_13 AC 87 ms
73,488 KB
testcase_14 AC 88 ms
73,344 KB
testcase_15 AC 87 ms
73,620 KB
testcase_16 AC 88 ms
73,456 KB
testcase_17 AC 87 ms
73,400 KB
testcase_18 AC 87 ms
73,260 KB
testcase_19 AC 87 ms
73,212 KB
testcase_20 AC 88 ms
73,336 KB
testcase_21 AC 88 ms
73,504 KB
testcase_22 AC 90 ms
73,328 KB
testcase_23 AC 95 ms
73,456 KB
testcase_24 AC 96 ms
73,348 KB
testcase_25 AC 89 ms
73,440 KB
testcase_26 AC 95 ms
73,408 KB
testcase_27 AC 91 ms
73,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
using PII = std::pair<int, int>;
using PLL = std::pair<ll, ll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define allpt(v) (v).begin(), (v).end()
#define allpt_c(v) (v).cbegin(), (v).cend()
#define allpt_r(v) (v).rbegin(), (v).rend()


const int mod = 1e9 + 7;
const string wsp = " ";
const string tb = "\t";
const string rt = "\n";

template <typename T>
void show1dvec(const vector<T> &v)
{
    if (v.size() == 0)
        return;
    int n = v.size() - 1;
    rep(i, n) cout << v[i] << wsp;
    cout << v[n] << rt;
    return;
}

template <typename T>
void show2dvec(const vector<vector<T>> &v)
{
    int n = v.size();
    rep(i, v[i].size()) show1dvec(v[i]);
}

template <typename T, typename S>
void show1dpair(const vector<pair<T, S>> &v)
{
    int n = v.size();
    rep(i, n) cout << v[i].first << wsp << v[i].second << rt;
    return;
}

template <typename T, typename S>
void pairzip(const vector<pair<T, S>> &v, vector<T> &t, vector<T> &s)
{
    int n = v.size();
    rep(i, n)
    {
        t.push_back(v[i].first);
        s.push_back(v[i].second);
    }
    return;
}

template <typename T>
void maxvec(vector<T> &v)
{
    T s = v[0];
    int n = v.size();
    rep(i, n - 1)
    {
        if (s > v[i + 1])
        {
            v[i + 1] = s;
        }
        s = v[i + 1];
    }
}

template <typename T, typename S>
bool myfind(T t, S s)
{
    return find(t.cbegin(), t.cend(), s) != t.cend();
}

const int maxint = 1e9;
struct timestamp;
vector<int> shortest;
vector<vector<pair<int, int>>> connective;

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    const int nmax = 1000001;
    int n;
    cin >> n;
    vector<vector<ll>> dp(nmax, vector<ll>(4, 0));
    rep(i, 4) dp[0][i] = 1;
    dp[1][1] = 1;
    dp[2][2] = 1;
    dp[3][1] = dp[3][2] = 1, dp[3][3] = 1;

    if (n >= 4)
    {
        rep2(i, 4, n + 1)
        {
            dp[i][1] = (dp[i - 1][2] + dp[i - 1][3]) % mod;
            dp[i][2] = (dp[i - 2][1] + dp[i - 2][3]) % mod;
            dp[i][3] = (dp[i - 3][1] + dp[i - 3][2]) % mod;
        }
    }

    cout << (dp[n][1] + dp[n][2] + dp[n][3]) % mod << rt;
    return 0;
}
0