結果

問題 No.1231 Make a Multiple of Ten
ユーザー Inazuma_110Inazuma_110
提出日時 2020-09-19 01:28:34
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 1,385 bytes
コンパイル時間 8,499 ms
コンパイル使用メモリ 401,448 KB
実行使用メモリ 18,076 KB
最終ジャッジ日時 2023-09-05 18:25:05
合計ジャッジ時間 8,224 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,356 KB
testcase_01 AC 2 ms
4,360 KB
testcase_02 AC 2 ms
4,356 KB
testcase_03 AC 1 ms
4,356 KB
testcase_04 AC 22 ms
9,920 KB
testcase_05 AC 19 ms
9,156 KB
testcase_06 AC 9 ms
5,612 KB
testcase_07 AC 23 ms
10,156 KB
testcase_08 AC 12 ms
7,320 KB
testcase_09 AC 6 ms
4,368 KB
testcase_10 AC 20 ms
9,296 KB
testcase_11 AC 25 ms
10,740 KB
testcase_12 AC 42 ms
17,216 KB
testcase_13 AC 45 ms
17,736 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 46 ms
18,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
// #include <atcoder/all>

using boost::multiprecision::cpp_int;
using namespace std;
// using namespace atcoder;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, n){
    cin >> v[i];
    v[i] %= 10;
  }
  vector<vector<int>> dp(n+10, vector<int>(10, -1));
  // dp[i][j] = iまでのカードでjにする最大枚数
  // rep(i, 10) dp[0][i] = 0;
  dp[0][v[0]] = 1;

  for (int i = 1; i <= n; ++i) {
    rep(j, 10) dp[i][j] = dp[i-1][j];
    dp[i][v[i]] = 1;
    rep(j, 10){
      // cout << i << ' ' << j << endl;
      int tmp = j - v[i];
      if(tmp < 0) tmp += 10;
      if(dp[i-1][tmp] == -1) continue;
      dp[i][j] = max(dp[i-1][j], dp[i-1][tmp] + 1);
      // else dp[i][j] = dp[i-1][j];
    }
  }

  // print(dp);

  if(dp[n-1][0] == -1) cout << 0 << endl;
  else cout << dp[n-1][0] << endl;


}
0