結果

問題 No.1231 Make a Multiple of Ten
ユーザー MisterMister
提出日時 2020-09-18 21:55:34
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 562 bytes
コンパイル時間 595 ms
コンパイル使用メモリ 73,696 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-05 18:18:33
合計ジャッジ時間 1,695 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 16 ms
4,376 KB
testcase_05 AC 14 ms
4,380 KB
testcase_06 AC 7 ms
4,376 KB
testcase_07 AC 16 ms
4,376 KB
testcase_08 AC 8 ms
4,380 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 15 ms
4,376 KB
testcase_11 AC 17 ms
4,376 KB
testcase_12 AC 31 ms
4,380 KB
testcase_13 AC 33 ms
4,380 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 33 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

constexpr int INF = 1 << 30;

void solve() {
    int n;
    std::cin >> n;

    std::vector<int> dp(10, -INF);
    dp[0] = 0;
    while (n--) {
        int x;
        std::cin >> x;
        x %= 10;

        auto ndp = dp;
        for (int y = 0; y < 10; ++y) {
            ndp[(x + y) % 10] = std::max(ndp[(x + y) % 10], dp[y] + 1);
        }
        std::swap(dp, ndp);
    }

    std::cout << dp[0] << "\n";
}

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

    solve();

    return 0;
}
0