Submission #58457793


Source Code Expand

/*Code by Leo2011*/
#include <bits/stdc++.h>

#define INF 0x3f3f3f3f
#define EPS 1e-8
#define FOR(i, l, r) for (int(i) = (l); (i) <= (r); ++(i))
#define log printf
#define IOS                      \
	ios::sync_with_stdio(false); \
	cin.tie(nullptr);            \
	cout.tie(nullptr);

using namespace std;

typedef __int128 i128;
typedef long long ll;
typedef pair<int, int> PII;

const int N = 30;
int n, a[N], ans = INF, sum;

template <typename T>

inline T read() {
	T sum = 0, fl = 1;
	char ch = getchar();
	for (; !isdigit(ch); ch = getchar())
		if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = sum * 10 + ch - '0';
	return sum * fl;
}

template <typename T>

inline void write(T x) {
	if (x < 0) {
		putchar('-'), write<T>(-x);
		return;
	}
	static T sta[35];
	int top = 0;
	do { sta[top++] = x % 10, x /= 10; } while (x);
	while (top) putchar(sta[--top] + 48);
}

void dfs(int group, int cnt) {
	if (group == n) {
		ans = min(ans, max(cnt, sum - cnt));
		return;
	}
	dfs(group + 1, cnt + a[group]);
	dfs(group + 1, cnt);
}

int main() {
	n = read<int>();
	FOR(i, 1, n) a[i] = read<int>(), sum += a[i];
	dfs(1, 0);
	write<int>(ans);
	return 0;
}
// 20组---》爆搜挂着机,打表出AC

Submission Info

Submission Time
Task C - Separated Lunch
User Leo2011
Language C++ 23 (Clang 16.0.6)
Score 300
Code Size 1274 Byte
Status AC
Exec Time 2 ms
Memory 3640 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 30
Set Name Test Cases
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt
Case Name Status Exec Time Memory
example_00.txt AC 1 ms 3512 KiB
example_01.txt AC 1 ms 3504 KiB
example_02.txt AC 1 ms 3440 KiB
hand_00.txt AC 2 ms 3508 KiB
hand_01.txt AC 2 ms 3396 KiB
hand_02.txt AC 2 ms 3460 KiB
hand_03.txt AC 1 ms 3504 KiB
hand_04.txt AC 2 ms 3564 KiB
hand_05.txt AC 2 ms 3512 KiB
random_00.txt AC 2 ms 3472 KiB
random_01.txt AC 2 ms 3512 KiB
random_02.txt AC 2 ms 3436 KiB
random_03.txt AC 1 ms 3368 KiB
random_04.txt AC 2 ms 3376 KiB
random_05.txt AC 1 ms 3460 KiB
random_06.txt AC 1 ms 3456 KiB
random_07.txt AC 2 ms 3412 KiB
random_08.txt AC 2 ms 3464 KiB
random_09.txt AC 1 ms 3368 KiB
random_10.txt AC 2 ms 3408 KiB
random_11.txt AC 2 ms 3640 KiB
random_12.txt AC 2 ms 3492 KiB
random_13.txt AC 2 ms 3636 KiB
random_14.txt AC 2 ms 3372 KiB
random_15.txt AC 2 ms 3512 KiB
random_16.txt AC 2 ms 3564 KiB
random_17.txt AC 2 ms 3520 KiB
random_18.txt AC 2 ms 3408 KiB
random_19.txt AC 1 ms 3516 KiB
random_20.txt AC 2 ms 3568 KiB