Submission #41717474


Source Code Expand

#include <bits/stdc++.h>
#define int long long
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> void chkmax(T& x, T y) { x = max(x, y); }
template <typename T> void chkmin(T& x, T y) { x = min(x, y); }
template <typename T> void read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
const int N = 65;
int n, k, sum, a[N];
signed main() {
	read(n); read(k);
	F(i, 1, n) read(a[i]);
	sort(a + 1, a + n + 1);
	vector <int> cur;
	F(i, 1, n) {
		int cnt = 0;
		for (int j: cur)
			if (j < a[i]) cnt++;
		if (cnt >= k) break;
		if (sum < a[i]) {
			vector <int> tt = cur;
			F(j, sum + 1, a[i] - 1) {
				cur.push_back(j);
				if (cur.size() > k) break;
			}
			for (int j: tt) cur.push_back(j + a[i]);
		} else {
			vector <int> nw;
			set <int> CUR;
			for (int j: cur) CUR.insert(j);
			for (int j: cur) {
				if (j < a[i] || CUR.count(j - a[i])) nw.push_back(j);
				if (j + a[i] > sum) nw.push_back(j + a[i]);
			} swap(cur, nw);
		} sum += a[i];
	}
	F(i, 1, k) cur.push_back(sum + i);
	sort(all(cur));
	F(i, 1, k) cout << cur[i - 1] << " ";
	return 0;
}

Submission Info

Submission Time
Task C - Mex of Subset Sum
User ast123
Language C++ (GCC 9.2.1)
Score 800
Code Size 1488 Byte
Status AC
Exec Time 266 ms
Memory 7316 KiB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:35:20: warning: comparison of integer expressions of different signedness: ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} and ‘long long int’ [-Wsign-compare]
   35 |     if (cur.size() > k) break;
      |         ~~~~~~~~~~~^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 800 / 800
Status
AC × 2
AC × 69
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt
All 00_sample_01.txt, 00_sample_02.txt, 01_rand1_01.txt, 01_rand1_02.txt, 01_rand1_03.txt, 01_rand1_04.txt, 01_rand1_05.txt, 01_rand1_06.txt, 01_rand1_07.txt, 01_rand1_08.txt, 01_rand1_09.txt, 01_rand1_10.txt, 01_rand1_11.txt, 01_rand1_12.txt, 01_rand1_13.txt, 01_rand1_14.txt, 01_rand1_15.txt, 01_rand1_16.txt, 01_rand1_17.txt, 01_rand1_18.txt, 01_rand1_19.txt, 01_rand1_20.txt, 01_rand1_21.txt, 01_rand1_22.txt, 01_rand1_23.txt, 01_rand1_24.txt, 01_rand1_25.txt, 01_rand1_26.txt, 01_rand1_27.txt, 01_rand1_28.txt, 01_rand1_29.txt, 01_rand1_30.txt, 01_rand1_31.txt, 01_rand1_32.txt, 01_rand1_33.txt, 02_rand2_01.txt, 02_rand2_02.txt, 02_rand2_03.txt, 02_rand2_04.txt, 02_rand2_05.txt, 02_rand2_06.txt, 02_rand2_07.txt, 02_rand2_08.txt, 02_rand2_09.txt, 02_rand2_10.txt, 02_rand2_11.txt, 02_rand2_12.txt, 02_rand2_13.txt, 02_rand2_14.txt, 02_rand2_15.txt, 02_rand2_16.txt, 02_rand2_17.txt, 03_rand3_01.txt, 03_rand3_02.txt, 03_rand3_03.txt, 03_rand3_04.txt, 03_rand3_05.txt, 03_rand3_06.txt, 04_handmade_01.txt, 04_handmade_02.txt, 04_handmade_03.txt, 04_handmade_04.txt, 04_handmade_05.txt, 04_handmade_06.txt, 04_handmade_07.txt, 04_handmade_08.txt, 04_handmade_09.txt, 04_handmade_10.txt, 04_handmade_11.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 8 ms 3492 KiB
00_sample_02.txt AC 2 ms 3616 KiB
01_rand1_01.txt AC 9 ms 3568 KiB
01_rand1_02.txt AC 10 ms 3612 KiB
01_rand1_03.txt AC 7 ms 3660 KiB
01_rand1_04.txt AC 20 ms 3772 KiB
01_rand1_05.txt AC 10 ms 3728 KiB
01_rand1_06.txt AC 9 ms 3680 KiB
01_rand1_07.txt AC 6 ms 3720 KiB
01_rand1_08.txt AC 13 ms 3680 KiB
01_rand1_09.txt AC 10 ms 3740 KiB
01_rand1_10.txt AC 7 ms 3700 KiB
01_rand1_11.txt AC 6 ms 3560 KiB
01_rand1_12.txt AC 12 ms 3552 KiB
01_rand1_13.txt AC 8 ms 3748 KiB
01_rand1_14.txt AC 15 ms 3612 KiB
01_rand1_15.txt AC 8 ms 3696 KiB
01_rand1_16.txt AC 13 ms 3668 KiB
01_rand1_17.txt AC 11 ms 3548 KiB
01_rand1_18.txt AC 8 ms 3568 KiB
01_rand1_19.txt AC 8 ms 3556 KiB
01_rand1_20.txt AC 11 ms 3616 KiB
01_rand1_21.txt AC 16 ms 3760 KiB
01_rand1_22.txt AC 12 ms 3572 KiB
01_rand1_23.txt AC 14 ms 3752 KiB
01_rand1_24.txt AC 19 ms 3776 KiB
01_rand1_25.txt AC 18 ms 4040 KiB
01_rand1_26.txt AC 21 ms 4048 KiB
01_rand1_27.txt AC 152 ms 5848 KiB
01_rand1_28.txt AC 160 ms 5656 KiB
01_rand1_29.txt AC 144 ms 5628 KiB
01_rand1_30.txt AC 13 ms 3784 KiB
01_rand1_31.txt AC 11 ms 3748 KiB
01_rand1_32.txt AC 14 ms 3568 KiB
01_rand1_33.txt AC 12 ms 3676 KiB
02_rand2_01.txt AC 6 ms 3608 KiB
02_rand2_02.txt AC 11 ms 3836 KiB
02_rand2_03.txt AC 13 ms 3624 KiB
02_rand2_04.txt AC 4 ms 3756 KiB
02_rand2_05.txt AC 11 ms 3760 KiB
02_rand2_06.txt AC 11 ms 3624 KiB
02_rand2_07.txt AC 12 ms 3620 KiB
02_rand2_08.txt AC 9 ms 3732 KiB
02_rand2_09.txt AC 11 ms 3744 KiB
02_rand2_10.txt AC 8 ms 3552 KiB
02_rand2_11.txt AC 8 ms 3784 KiB
02_rand2_12.txt AC 44 ms 4140 KiB
02_rand2_13.txt AC 12 ms 3676 KiB
02_rand2_14.txt AC 10 ms 3728 KiB
02_rand2_15.txt AC 18 ms 3864 KiB
02_rand2_16.txt AC 13 ms 3612 KiB
02_rand2_17.txt AC 18 ms 3624 KiB
03_rand3_01.txt AC 189 ms 6108 KiB
03_rand3_02.txt AC 189 ms 6408 KiB
03_rand3_03.txt AC 188 ms 6412 KiB
03_rand3_04.txt AC 80 ms 4864 KiB
03_rand3_05.txt AC 80 ms 5032 KiB
03_rand3_06.txt AC 83 ms 4908 KiB
04_handmade_01.txt AC 2 ms 3492 KiB
04_handmade_02.txt AC 135 ms 5180 KiB
04_handmade_03.txt AC 128 ms 5108 KiB
04_handmade_04.txt AC 257 ms 6816 KiB
04_handmade_05.txt AC 266 ms 7316 KiB
04_handmade_06.txt AC 134 ms 5676 KiB
04_handmade_07.txt AC 235 ms 6872 KiB
04_handmade_08.txt AC 41 ms 4568 KiB
04_handmade_09.txt AC 2 ms 3496 KiB
04_handmade_10.txt AC 2 ms 3476 KiB
04_handmade_11.txt AC 2 ms 3596 KiB