結果

問題 No.1231 Make a Multiple of Ten
ユーザー asdf1asdf1
提出日時 2018-12-31 18:11:07
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 929 bytes
コンパイル時間 1,319 ms
コンパイル使用メモリ 158,420 KB
実行使用メモリ 28,544 KB
最終ジャッジ日時 2024-04-20 22:09:23
合計ジャッジ時間 2,416 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
28,416 KB
testcase_01 AC 16 ms
28,416 KB
testcase_02 AC 15 ms
28,416 KB
testcase_03 AC 16 ms
28,416 KB
testcase_04 AC 29 ms
28,416 KB
testcase_05 AC 26 ms
28,416 KB
testcase_06 WA -
testcase_07 AC 30 ms
28,416 KB
testcase_08 AC 23 ms
28,416 KB
testcase_09 AC 19 ms
28,416 KB
testcase_10 AC 31 ms
28,416 KB
testcase_11 WA -
testcase_12 AC 37 ms
28,416 KB
testcase_13 AC 45 ms
28,416 KB
testcase_14 AC 17 ms
28,416 KB
testcase_15 AC 44 ms
28,416 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;
        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