結果

問題 No.1231 Make a Multiple of Ten
ユーザー takumattakumat
提出日時 2020-09-18 22:42:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,279 bytes
コンパイル時間 1,844 ms
コンパイル使用メモリ 174,872 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-22 10:07:49
合計ジャッジ時間 3,010 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 40 ms
6,944 KB
testcase_05 AC 36 ms
6,944 KB
testcase_06 AC 15 ms
6,940 KB
testcase_07 AC 42 ms
6,944 KB
testcase_08 AC 15 ms
6,940 KB
testcase_09 AC 10 ms
6,940 KB
testcase_10 AC 37 ms
6,940 KB
testcase_11 AC 45 ms
6,944 KB
testcase_12 WA -
testcase_13 AC 86 ms
6,940 KB
testcase_14 WA -
testcase_15 AC 86 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 nowVal)
{
	int ans = MOD_NUM;

	if (lsbs.find(nowVal) != lsbs.end()) {
		return 1;
	}
	for (int i = 1; i < nowVal; i++) {
		int val1, val2;
		if (lsbs.find(i) != lsbs.end()) {
			val1 = 1;
			lsbs[i]--;
			val2 = dfs(lsbs, nowVal - i);
			lsbs[i]++;
		}
		else {
			val1 = dfs(lsbs, i);
			val2 = dfs(lsbs, nowVal - i);
		}

		ans = std::min(ans, val1 + val2);
	}
	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 - 1;
	int mod = ttl % 10;
	if (lsbs.find(mod) == lsbs.end()) {
		ans = N - dfs(lsbs, ttl % 10);
	}

	printf("%d\n", ans);
}
0