結果

問題 No.1231 Make a Multiple of Ten
ユーザー MATSUMATMATSUMAT
提出日時 2018-12-31 18:33:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 744 bytes
コンパイル時間 1,385 ms
コンパイル使用メモリ 165,316 KB
実行使用メモリ 28,352 KB
最終ジャッジ日時 2023-09-05 18:07:05
合計ジャッジ時間 2,787 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 44 ms
14,832 KB
testcase_05 AC 38 ms
13,340 KB
testcase_06 AC 16 ms
7,284 KB
testcase_07 AC 45 ms
15,288 KB
testcase_08 AC 18 ms
10,464 KB
testcase_09 AC 11 ms
5,676 KB
testcase_10 AC 40 ms
13,928 KB
testcase_11 AC 48 ms
16,232 KB
testcase_12 AC 87 ms
27,136 KB
testcase_13 AC 91 ms
28,344 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 91 ms
28,352 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];
    if(A[i]==0 or A[i]>1e9){
      cout << "制約を守れ!" << endl;
    }
    A[i] %= 10LL;
    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 < N; i++) {
    for (int j = 0; j <= 9; j++) {
      dp[i + 1][(j + A[i]) % 10LL] = min(dp[i + 1][(j + A[i]) % 10LL], dp[i][j] + 1LL);
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
    }
  }
  
  cout << N - dp[N][sum % 10LL] << endl;
  return 0;
}
0