結果

問題 No.1231 Make a Multiple of Ten
ユーザー ninoinuininoinui
提出日時 2020-09-18 22:12:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 716 bytes
コンパイル時間 2,052 ms
コンパイル使用メモリ 202,416 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 18:21:43
合計ジャッジ時間 3,200 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 18 ms
4,376 KB
testcase_05 AC 16 ms
4,380 KB
testcase_06 AC 7 ms
4,376 KB
testcase_07 AC 19 ms
4,376 KB
testcase_08 AC 9 ms
4,380 KB
testcase_09 AC 5 ms
4,380 KB
testcase_10 AC 16 ms
4,376 KB
testcase_11 AC 19 ms
4,380 KB
testcase_12 AC 34 ms
4,376 KB
testcase_13 AC 36 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 36 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template<typename T, typename U> void cmax(T &a, U b) { if (a < b) a = b; }
template<typename T, typename U> void cmin(T &a, U b) { if (a > b) a = b; }

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);

  long acc = accumulate(A.begin(), A.end(), 0L);
  int X = acc % 10;

  vector<int> DP(10, INT_MAX);
  DP.at(0) = 0;
  for (auto a : A) {
    auto C = DP;
    for (int i = 0; i < 10; i++) {
      if (DP.at(i) == INT_MAX) continue;
      int next = (i + a) % 10;
      cmin(C.at(next), DP.at(i) + 1);
    }
    DP = C;
  }
  cout << N - DP.at(X) << "\n";
}
0