結果

問題 No.1231 Make a Multiple of Ten
ユーザー parsee1053parsee1053
提出日時 2020-09-27 14:48:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 748 bytes
コンパイル時間 726 ms
コンパイル使用メモリ 87,032 KB
実行使用メモリ 27,248 KB
最終ジャッジ日時 2023-09-13 01:15:43
合計ジャッジ時間 3,400 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 50 ms
14,080 KB
testcase_05 AC 45 ms
12,760 KB
testcase_06 AC 19 ms
6,688 KB
testcase_07 AC 53 ms
14,564 KB
testcase_08 AC 21 ms
9,580 KB
testcase_09 AC 12 ms
5,484 KB
testcase_10 AC 47 ms
13,280 KB
testcase_11 AC 56 ms
15,392 KB
testcase_12 AC 102 ms
25,884 KB
testcase_13 AC 106 ms
27,168 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 107 ms
27,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  vector<vector<ll> > dp(n + 1, vector<ll>(10, -1));
  dp[0][0] = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= 9; ++j) {
      dp[i][j] = max(dp[i][j], dp[i - 1][j]);
      if (dp[i - 1][j] != -1) {
        dp[i][(j + a[i]) % 10] = max(dp[i][(j + a[i]) % 10], dp[i - 1][j] + 1);
      }
    }
  }
  cout << dp[n][0] << endl;
  return 0;
}
0