結果
問題 | No.1231 Make a Multiple of Ten |
ユーザー |
|
提出日時 | 2020-09-18 22:58:35 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 283 ms / 2,000 ms |
コード長 | 1,370 bytes |
コンパイル時間 | 1,633 ms |
コンパイル使用メモリ | 175,128 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-23 13:52:15 |
合計ジャッジ時間 | 3,575 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 13 |
ソースコード
#include <bits/stdc++.h>//#include <atcoder/all>typedef unsigned long long ULLONG;typedef long long LLONG;static const LLONG MOD_NUM = 1000000007; //998244353;template<class _T> static void get(_T& a) {std::cin >> a;}template<class _T> static void get(_T& a, _T& b) {std::cin >> a >> b;}template<class _T> static void get(_T& a, _T& b, _T& c) {std::cin >> a >> b >> c;}template <class _T> static _T tp_abs(_T a) {if (a < (_T)0) {a *= (_T)-1;}return a;}static void A();int main(){A();fflush(stdout);return 0;}static int dfs(std::map<int, int>& lsbs, int nowlsb, int nowcnt, int nowval, int mod){if (nowval == mod) {return nowcnt;}else if (nowlsb > 9) {return -1;}int ans = MOD_NUM;int cnt = 0;if (lsbs.find(nowlsb) != lsbs.end()) {cnt = lsbs[nowlsb];}for (int i = 0; (i <= cnt) && (i < 10); i++) {int ret = dfs(lsbs, nowlsb + 1, nowcnt + i, (nowval + i * nowlsb) % 10, mod);if (ret >= 0) {ans = std::min(ans, ret);}}return ans;}static void A(){int N;get(N);std::map<int, int> lsbs;int ai, ttl = 0;for (int i = 0; i < N; i++) {get(ai);ttl += ai % 10;lsbs[ai % 10]++;}int ans = N;int mod = ttl % 10;if (mod) {if (lsbs.find(mod) != lsbs.end()) {ans = N - 1;}else {ans = N - dfs(lsbs, 1, 0, 0, mod);}}printf("%d\n", ans);}