結果

問題 No.1231 Make a Multiple of Ten
ユーザー Inazuma_110Inazuma_110
提出日時 2020-09-18 22:36:00
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,579 bytes
コンパイル時間 9,751 ms
コンパイル使用メモリ 410,060 KB
実行使用メモリ 4,516 KB
最終ジャッジ日時 2023-09-04 11:13:02
合計ジャッジ時間 6,441 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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;

vector<vector<int>> table2;

void f(vector<int> table, int sum, int b){
  if(sum == 10){
    table2.push_back(table);
    return;
  }

  for (int i = b; i < 10; ++i) {
    auto tmp = table;
    tmp.push_back(i);
    if(sum + i <= 10) f(tmp, sum + i, i);
  }
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  vector<int> d(10);
  rep(i, n){
    cin >> v[i];
    v[i] %= 10;
    d[v[i]]++;
  }
  ll res = d[0];

  f(vector<int>(), 0, 1);

  sort(ALL(table2), [](auto const& a, auto const& b){return a.size() > b.size();});

  for(auto table : table2){
    vector<int> tmp(10);
    for(auto val : table){
      tmp[val]++;
    }
    int cnt = INT_MAX;
    for (int i = 1; i < 10; ++i) {
      if(tmp[i] >= 1){
        chmin(cnt, d[i] / tmp[i]);
      }
    }

    res += cnt * int(table.size());
    for (int i = 1; i < 10; ++i) {
      d[i] -= cnt * tmp[i];
    }
  }


  cout << res << endl;
}
0