結果

問題 No.770 Median Sequence
ユーザー PachicobuePachicobue
提出日時 2018-12-19 16:11:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 431 ms / 2,000 ms
コード長 1,161 bytes
コンパイル時間 1,073 ms
コンパイル使用メモリ 79,488 KB
実行使用メモリ 355,716 KB
最終ジャッジ日時 2023-10-25 23:56:07
合計ジャッジ時間 4,447 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 13 ms
14,364 KB
testcase_09 AC 43 ms
40,500 KB
testcase_10 AC 14 ms
15,684 KB
testcase_11 AC 6 ms
7,236 KB
testcase_12 AC 409 ms
323,772 KB
testcase_13 AC 183 ms
154,020 KB
testcase_14 AC 95 ms
83,532 KB
testcase_15 AC 296 ms
244,044 KB
testcase_16 AC 45 ms
42,612 KB
testcase_17 AC 431 ms
355,716 KB
testcase_18 AC 431 ms
355,452 KB
testcase_19 AC 429 ms
355,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using ll = long long;
constexpr ll MOD = 1000000007;
template <typename T>
std::vector<T> Vec(const std::size_t n, T v) { return std::vector<T>(n, v); }
template <class... Args>
auto Vec(const std::size_t n, Args... args) { return std::vector<decltype(Vec(args...))>(n, Vec(args...)); }
int main()
{
    int N;
    std::cin >> N;
    auto dp = Vec(2, N + 1, N + 1, 0LL);  // 現在の坂成分で下がったか;Aiまで決定;Ai = h;
    auto sum = Vec(2, N + 1, N + 1, 0LL);
    dp[0][0][0] = 1LL;
    std::fill(sum[0][0].begin(), sum[0][0].end(), 1LL);
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            (dp[0][i][j] += sum[0][i - 1][j] + sum[1][i - 1][j - 1]) %= MOD;
            (dp[1][i][j] += dp[1][i - 1][j] + (j == N ? 0LL : dp[1][i - 1][j + 1])) %= MOD;
            if (j < N and i + j >= N) { (dp[1][i][j] += dp[0][i + j - N][j + 1]) %= MOD; }
            sum[0][i][j] = (sum[0][i][j - 1] + dp[0][i][j]) % MOD;
            sum[1][i][j] = (sum[1][i][j - 1] + dp[1][i][j]) % MOD;
        }
    }
    std::cout << (sum[0][N][N] + sum[1][N][N]) % MOD << std::endl;
    return 0;
}
0