結果

問題 No.1231 Make a Multiple of Ten
ユーザー milanis48663220milanis48663220
提出日時 2020-09-18 21:34:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 852 bytes
コンパイル時間 675 ms
コンパイル使用メモリ 82,284 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 18:10:25
合計ジャッジ時間 1,778 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int cnt[10];

int dp[10][10];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int N; cin >> N;
    for(int i = 0; i < N; i++) {
        int a; cin >> a;
        cnt[a%10]++;
    }
    const int INF = 1e8;
    dp[0][0] = cnt[0];
    for(int i = 1; i <= 9; i++) dp[0][i] = -INF;
    for(int i = 1; i <= 9; i++){
        for(int j = 0; j <= 9; j++){
            dp[i][j] = -INF;
        }
        for(int j = 0; j <= cnt[i]; j++){
            for(int k = 0; k <= 9; k++){
                int nx = (k+i*j)%10;
                dp[i][nx] = max(dp[i][nx], dp[i-1][k]+j);
            }
        }
    }
    cout << dp[9][0] << endl;
}
0