結果

問題 No.1231 Make a Multiple of Ten
ユーザー mikianaaamikianaaa
提出日時 2020-09-24 15:27:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 943 bytes
コンパイル時間 1,515 ms
コンパイル使用メモリ 168,332 KB
実行使用メモリ 28,040 KB
最終ジャッジ日時 2023-09-10 13:28:13
合計ジャッジ時間 3,253 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 28 ms
14,388 KB
testcase_05 AC 25 ms
13,040 KB
testcase_06 AC 11 ms
6,988 KB
testcase_07 AC 29 ms
15,192 KB
testcase_08 AC 16 ms
9,868 KB
testcase_09 AC 7 ms
5,388 KB
testcase_10 AC 27 ms
13,612 KB
testcase_11 AC 32 ms
15,648 KB
testcase_12 AC 56 ms
26,740 KB
testcase_13 AC 59 ms
28,040 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 58 ms
27,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

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

    int N;
    cin >> N;
    ll MOD = 10;
    vector<ll> A(N);
    vector<vector<ll>> dp(
        N + 1, vector<ll>(10, -1)); // i番目まで選んだ時のMODjの時の最大枚数。
    rep(i, N) { cin >> A[i]; }

    dp[0][0] = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 10; j++) {
            if (dp[i][j] == -1)
                continue;
            // 選ぶ
            int n = (j + A[i]) % MOD;
            dp[i + 1][n] = max(dp[i + 1][n], dp[i][j] + 1);
            // 選ばない
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
        }
    }

    cout << dp[N][0] << endl;
}
0