結果

問題 No.1231 Make a Multiple of Ten
ユーザー asdf1asdf1
提出日時 2018-12-31 18:12:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 962 bytes
コンパイル時間 1,176 ms
コンパイル使用メモリ 144,708 KB
実行使用メモリ 28,488 KB
最終ジャッジ日時 2023-09-05 18:06:36
合計ジャッジ時間 2,402 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,428 KB
testcase_01 AC 2 ms
5,476 KB
testcase_02 AC 2 ms
5,480 KB
testcase_03 AC 2 ms
5,500 KB
testcase_04 AC 19 ms
16,440 KB
testcase_05 AC 17 ms
14,300 KB
testcase_06 AC 8 ms
9,780 KB
testcase_07 AC 19 ms
16,620 KB
testcase_08 AC 9 ms
12,008 KB
testcase_09 AC 6 ms
7,628 KB
testcase_10 AC 17 ms
16,232 KB
testcase_11 AC 21 ms
16,820 KB
testcase_12 AC 25 ms
5,128 KB
testcase_13 AC 38 ms
28,376 KB
testcase_14 AC 2 ms
5,552 KB
testcase_15 AC 38 ms
28,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
const long long LINF=1e18;
using namespace std;
//-------------------------↓↓↓↓↓↓------------------------

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

    long long n, a[2 * 100000 + 10], sum = 0, need, dp[2 * 100000 + 10][15];

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

    if(sum % 10 == 0)cout << n << "\n";
    else{
        need = sum % 10;

        for(int i = 0; i < n + 5; i++){
            for(int j = 0; j < 13; j++){
                dp[i][j] = LINF;
            }
        }

        dp[0][0] = 0;
        if(a[0] != 0){
        dp[0][a[0]] = 1;
        }
        for(int i = 1; i < n; i++){
            for(int j = 0; j < 10; j++){
                dp[i][(j + a[i]) % 10] = min(dp[i - 1][(j + a[i]) % 10], dp[i - 1][j] + 1);
            }
        }

        cout << n - dp[n - 1][need] << "\n";
    }
    return 0;
}
0