結果

問題 No.1231 Make a Multiple of Ten
ユーザー takumattakumat
提出日時 2020-09-18 22:02:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,244 bytes
コンパイル時間 1,838 ms
コンパイル使用メモリ 173,424 KB
実行使用メモリ 11,492 KB
最終ジャッジ日時 2023-09-04 10:42:56
合計ジャッジ時間 30,105 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 nowlsb, int nowCnt, int nowVal, int goal)
{
	if (nowVal == goal) {
		return nowCnt;
	}
	else if (nowlsb > 9) {
		return -1;
	}
	
	int cnt = 0;
	if (lsbs.find(nowlsb) != lsbs.end()) {
		cnt = lsbs[nowlsb];
	}

	int ans = MOD_NUM;
	for (int i = 0; (i <= cnt) && (i < 10); i++) {
		int ret = dfs(lsbs, nowlsb + 1, nowCnt + i, (nowVal + (i * nowlsb)) % 10, goal);
		if (ret >= 0) {
			ans = std::min(ans, ret);
		}
	}
	return ans;
}

static void A()
{
	int N;
	get(N);
	
	int ai, ttl = 0;
	std::map<int, int> lsbs;
	for (int i = 0; i < N; i++) {
		get(ai);
		ttl += ai % 10;
		lsbs[ai % 10]++;
	}

	printf("%d\n", N - dfs(lsbs, 1, 0, 0, ttl % 10));
}
0