結果

問題 No.1231 Make a Multiple of Ten
ユーザー MATSUMATMATSUMAT
提出日時 2018-12-31 15:36:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 109 ms / 2,000 ms
コード長 644 bytes
コンパイル時間 1,504 ms
コンパイル使用メモリ 165,112 KB
実行使用メモリ 28,616 KB
最終ジャッジ日時 2023-09-05 18:06:40
合計ジャッジ時間 3,014 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 48 ms
15,100 KB
testcase_05 AC 42 ms
13,400 KB
testcase_06 AC 18 ms
7,360 KB
testcase_07 AC 50 ms
15,352 KB
testcase_08 AC 20 ms
10,464 KB
testcase_09 AC 12 ms
5,804 KB
testcase_10 AC 46 ms
13,944 KB
testcase_11 AC 54 ms
16,120 KB
testcase_12 AC 103 ms
27,360 KB
testcase_13 AC 109 ms
28,616 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 109 ms
28,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
  long long N, sum = 0;
  cin >> N;
  long long A[N];
  for(int i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
  }
  long long dp[N + 5][15];
  for(int i = 0; i < N + 5; i++) {
    for(int j = 0; j < 15; j++) {
      if (j == 0) {
        dp[i][j] = 0;
      }else {
        dp[i][j] = N;
      }
    }
  }
  for (int i = 0; i <= 9; i++) {
    for (int j = 0; j < N; j++) {
      dp[j + 1][(i + A[j]) % 10LL] = min(dp[j + 1][(i + A[j]) % 10LL], dp[j][i] + 1LL);
      dp[j + 1][i] = min(dp[j + 1][i], dp[j][i]);
    }
  }
  cout << N - dp[N][sum % 10LL] << endl;
  return 0;
}
0