結果

問題 No.1231 Make a Multiple of Ten
ユーザー t33ft33f
提出日時 2020-09-18 22:14:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 768 bytes
コンパイル時間 724 ms
コンパイル使用メモリ 72,040 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 18:21:50
合計ジャッジ時間 1,877 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    const int INF = 1<<30;
    int dp[2][10] = {};
    fill(dp[0], dp[0]+10, -INF);
    fill(dp[1], dp[1]+10, -INF);
    int cur = 0, prev = 1;
    dp[prev][0] = 0;
    for (int i = 1; i < 10; i++) dp[prev][i] = -INF;
    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        for (int i = 0; i < 10; i++) {
            int j = (i + a) % 10;
            if (dp[prev][i] >= 0)
                dp[cur][j] = max(dp[prev][j], 1 + dp[prev][i]);
            else
                dp[cur][j] = dp[prev][j];
        }
        // for (int j = 0; j < 10; j++) cerr << dp[cur][j] << " "; cerr << endl;
        swap(cur, prev);
    }
    cout << max(0, dp[prev][0]) << endl;
}
0