結果

問題 No.1231 Make a Multiple of Ten
ユーザー merom686merom686
提出日時 2020-09-18 21:43:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 887 bytes
コンパイル時間 942 ms
コンパイル使用メモリ 84,480 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-05 18:13:09
合計ジャッジ時間 1,895 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

template <class T>
void chmin(T &a, T b) {
    if (b < a) a = b;
}

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

    int n;
    cin >> n;

    int b[10] = {};
    int s = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        a %= 10;

        b[a]++;
        s += a;
    }
    s %= 10;

    int dp[10];
    for (int i = 0; i < 10; i++) {
        dp[i] = 1 << 30;
        chmin(b[i], 10);
    }
    dp[0] = 0;

    for (int a = 1; a < 10; a++) {
        for (int k = 1; k <= b[a]; k++) {
            for (int i = 0; i < 10; i++) {
                chmin(dp[i], dp[(i - a * k + 100) % 10] + k);
            }
        }
    }

    cout << n - dp[s] << endl;

    return 0;
}
0