結果

問題 No.1231 Make a Multiple of Ten
ユーザー face4face4
提出日時 2020-09-22 09:43:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 799 bytes
コンパイル時間 609 ms
コンパイル使用メモリ 69,372 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-08 03:04:09
合計ジャッジ時間 1,951 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<cstring>
using namespace std;

int main(){
    int n;
    cin >> n;
    int x[10] = {};
    for(int i = 0; i < n; i++){
        int a;  cin >> a;
        x[a%10]++;
    }
    int ans = x[0];
    for(int i = 1; i < 10; i++){
        if(x[i]%10) ans += x[i]/10*10, x[i] %= 10;
        else        ans += max(0, x[i]-10), x[i] = min(x[i], 10);
    }
    int dp[1001];
    memset(dp, -1, sizeof(dp));
    dp[0] = 0;
    for(int i = 1; i < 10; i++){
        for(int j = 0; j < x[i]; j++){
            for(int k = 1000-i; k >= 0; k--){
                if(dp[k] == -1) continue;
                dp[k+i] = max(dp[k+i], dp[k]+1);
            }
        }
    }
    int ma = 0;
    for(int i = 0; i < 1000; i += 10)   ma = max(ma, dp[i]);
    cout << ans+ma << endl;
    return 0;
}
0