結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,596 KB
testcase_01 AC 2 ms
5,392 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 3 ms
5,436 KB
testcase_04 AC 18 ms
14,820 KB
testcase_05 AC 16 ms
14,440 KB
testcase_06 AC 8 ms
9,748 KB
testcase_07 AC 18 ms
16,168 KB
testcase_08 AC 10 ms
11,796 KB
testcase_09 AC 5 ms
7,636 KB
testcase_10 AC 17 ms
14,340 KB
testcase_11 AC 19 ms
16,536 KB
testcase_12 AC 25 ms
4,924 KB
testcase_13 AC 36 ms
28,296 KB
testcase_14 AC 2 ms
5,484 KB
testcase_15 AC 37 ms
28,388 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;
    //assert(n <= 2 * 100000);
    //assert(n >= 1);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        assert(a[i] <= 1000000000);
        //assert(a[i] >= 1);
        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