結果

問題 No.1231 Make a Multiple of Ten
ユーザー rinrinta121rinrinta121
提出日時 2020-09-19 00:37:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 839 bytes
コンパイル時間 1,384 ms
コンパイル使用メモリ 164,540 KB
実行使用メモリ 12,032 KB
最終ジャッジ日時 2023-09-05 18:24:51
合計ジャッジ時間 2,840 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,172 KB
testcase_01 AC 6 ms
11,332 KB
testcase_02 AC 5 ms
11,212 KB
testcase_03 AC 6 ms
11,364 KB
testcase_04 AC 41 ms
11,524 KB
testcase_05 AC 37 ms
11,480 KB
testcase_06 AC 18 ms
11,352 KB
testcase_07 AC 42 ms
11,580 KB
testcase_08 AC 18 ms
11,500 KB
testcase_09 AC 14 ms
11,540 KB
testcase_10 AC 39 ms
11,484 KB
testcase_11 AC 45 ms
11,620 KB
testcase_12 AC 79 ms
12,032 KB
testcase_13 AC 83 ms
11,920 KB
testcase_14 AC 6 ms
11,156 KB
testcase_15 AC 85 ms
11,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef pair<ll, ll> P;

const int mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;

int dp[200050][10];

int main()
{
    int n; cin >> n;
    int a[n];
    rep(i,n){
        int x; cin >> x;
        a[i] = x%10;
    }
    for(int i = 0; i < 200050; i++){
        for(int j = 0; j < 10; j++) dp[i][j] = -inf;
    }
    dp[0][0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 10; j++){
            if(j - a[i] >= 0) dp[i+1][j] = max(dp[i][j],dp[i][j-a[i]]+1);
            else dp[i+1][j] = max(dp[i][j],dp[i][10+j-a[i]]+1);
        }
    }
    cout << dp[n][0] << endl;
}
0