Submission #935200

# Submission time Handle Problem Language Result Execution time Memory
935200 2024-02-28T19:32:49 Z tvladm2009 Council (JOI23_council) C++17
33 / 100
4000 ms 12224 KB
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
 
using namespace std;
template<typename T1, typename T2> inline void chkmin(T1 &a, T2 b) {if (a > b) a = b;}
template<typename T1, typename T2> inline void chkmax(T1 &a, T2 b) {if (a < b) a = b;}
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define left left228
#define right right228
#define y1 y1228
#define mp make_pair
#define pb push_back
#define y2 y2228
#define rank rank228
using ll = long long;
using ld = long double; 
const string FILENAME = "input";
const int MAXN = 300228;
const int MAXM = 20 + 7;

int n, m;
int a[MAXN], cnt[MAXM];
pair<int, int> best[1 << 20];

int get_best(int mask, int i) {
	if (best[mask].first == i) {
		return __builtin_popcount(a[best[mask].second] & mask);
	}
	return __builtin_popcount(a[best[mask].first] & mask);
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//read(FILENAME);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < m; j++) {
			int x;
			cin >> x;
			if (x == 1) {
				a[i] |= (1 << j);
				cnt[j]++;
			}
		}
	}
	// asta merge cu sos
	for (int mask = 0; mask < (1 << m); mask++) {
		pair<int, int> cost = mp(m + 1, m + 1);
		best[mask] = mp(-1, -1);
		for (int i = 1; i <= n; i++) {
			if (__builtin_popcount(mask & a[i]) <= cost.first) {
				cost.second = cost.first;
				cost.first = __builtin_popcount(mask & a[i]);
				best[mask].second = best[mask].first;
				best[mask].first = i;
			} else if (__builtin_popcount(mask & a[i]) <= cost.second) {
				cost.second = __builtin_popcount(mask & a[i]);
				best[mask].second = i;	
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		vector<int> critic;
		int mask = 0;
		int sol = 0;
		for (int j = 0; j < m; j++) {
			int aux = cnt[j];
			if (a[i] & (1 << j)) {
				aux--;
			}
			if (aux == n / 2) {
				critic.pb(j);
				mask |= (1 << j);
			} else if (aux > n / 2) {
				sol++;
			}
		}
		sol += sz(critic) - get_best(mask, i);
		cout << sol << '\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2516 KB Output is correct
5 Correct 192 ms 8828 KB Output is correct
6 Correct 911 ms 8836 KB Output is correct
7 Correct 20 ms 8792 KB Output is correct
8 Correct 107 ms 8824 KB Output is correct
9 Correct 1109 ms 8840 KB Output is correct
10 Correct 21 ms 8844 KB Output is correct
11 Correct 119 ms 8828 KB Output is correct
12 Correct 1111 ms 8844 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2508 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2392 KB Output is correct
31 Correct 2 ms 2392 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2648 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2648 KB Output is correct
40 Correct 2 ms 2400 KB Output is correct
41 Correct 3 ms 2404 KB Output is correct
42 Correct 1 ms 2396 KB Output is correct
43 Correct 3 ms 2404 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 4 ms 2396 KB Output is correct
46 Correct 21 ms 4696 KB Output is correct
47 Correct 3 ms 4700 KB Output is correct
48 Correct 13 ms 4700 KB Output is correct
49 Correct 4 ms 4696 KB Output is correct
50 Correct 15 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2516 KB Output is correct
5 Correct 192 ms 8828 KB Output is correct
6 Correct 911 ms 8836 KB Output is correct
7 Correct 20 ms 8792 KB Output is correct
8 Correct 107 ms 8824 KB Output is correct
9 Correct 1109 ms 8840 KB Output is correct
10 Correct 21 ms 8844 KB Output is correct
11 Correct 119 ms 8828 KB Output is correct
12 Correct 1111 ms 8844 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2508 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2392 KB Output is correct
31 Correct 2 ms 2392 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2648 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2648 KB Output is correct
40 Correct 2 ms 2400 KB Output is correct
41 Correct 3 ms 2404 KB Output is correct
42 Correct 1 ms 2396 KB Output is correct
43 Correct 3 ms 2404 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 4 ms 2396 KB Output is correct
46 Correct 21 ms 4696 KB Output is correct
47 Correct 3 ms 4700 KB Output is correct
48 Correct 13 ms 4700 KB Output is correct
49 Correct 4 ms 4696 KB Output is correct
50 Correct 15 ms 4700 KB Output is correct
51 Execution timed out 4043 ms 6896 KB Time limit exceeded
52 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 45 ms 5212 KB Output is correct
3 Correct 70 ms 2096 KB Output is correct
4 Correct 49 ms 4492 KB Output is correct
5 Correct 76 ms 5204 KB Output is correct
6 Correct 46 ms 4548 KB Output is correct
7 Correct 68 ms 5200 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 2 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 45 ms 5212 KB Output is correct
3 Correct 70 ms 2096 KB Output is correct
4 Correct 49 ms 4492 KB Output is correct
5 Correct 76 ms 5204 KB Output is correct
6 Correct 46 ms 4548 KB Output is correct
7 Correct 68 ms 5200 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 2 ms 2396 KB Output is correct
18 Correct 1 ms 2512 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1272 ms 9996 KB Output is correct
21 Correct 748 ms 9296 KB Output is correct
22 Correct 750 ms 9292 KB Output is correct
23 Correct 995 ms 10400 KB Output is correct
24 Correct 997 ms 6840 KB Output is correct
25 Correct 1201 ms 9868 KB Output is correct
26 Correct 1214 ms 9868 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 2 ms 2516 KB Output is correct
37 Correct 1 ms 2392 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2392 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 1 ms 2512 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 2 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 45 ms 5212 KB Output is correct
3 Correct 70 ms 2096 KB Output is correct
4 Correct 49 ms 4492 KB Output is correct
5 Correct 76 ms 5204 KB Output is correct
6 Correct 46 ms 4548 KB Output is correct
7 Correct 68 ms 5200 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 2 ms 2396 KB Output is correct
18 Correct 1 ms 2512 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1272 ms 9996 KB Output is correct
21 Correct 748 ms 9296 KB Output is correct
22 Correct 750 ms 9292 KB Output is correct
23 Correct 995 ms 10400 KB Output is correct
24 Correct 997 ms 6840 KB Output is correct
25 Correct 1201 ms 9868 KB Output is correct
26 Correct 1214 ms 9868 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 2 ms 2516 KB Output is correct
37 Correct 1 ms 2392 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2392 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 1 ms 2512 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 2 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Execution timed out 4058 ms 12224 KB Time limit exceeded
48 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 45 ms 5212 KB Output is correct
3 Correct 70 ms 2096 KB Output is correct
4 Correct 49 ms 4492 KB Output is correct
5 Correct 76 ms 5204 KB Output is correct
6 Correct 46 ms 4548 KB Output is correct
7 Correct 68 ms 5200 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 2 ms 2396 KB Output is correct
18 Correct 1 ms 2512 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1272 ms 9996 KB Output is correct
21 Correct 748 ms 9296 KB Output is correct
22 Correct 750 ms 9292 KB Output is correct
23 Correct 995 ms 10400 KB Output is correct
24 Correct 997 ms 6840 KB Output is correct
25 Correct 1201 ms 9868 KB Output is correct
26 Correct 1214 ms 9868 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 2 ms 2516 KB Output is correct
37 Correct 1 ms 2392 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2392 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 1 ms 2512 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 2 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Execution timed out 4058 ms 12224 KB Time limit exceeded
48 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2516 KB Output is correct
5 Correct 192 ms 8828 KB Output is correct
6 Correct 911 ms 8836 KB Output is correct
7 Correct 20 ms 8792 KB Output is correct
8 Correct 107 ms 8824 KB Output is correct
9 Correct 1109 ms 8840 KB Output is correct
10 Correct 21 ms 8844 KB Output is correct
11 Correct 119 ms 8828 KB Output is correct
12 Correct 1111 ms 8844 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2508 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2392 KB Output is correct
31 Correct 2 ms 2392 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2648 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2648 KB Output is correct
40 Correct 2 ms 2400 KB Output is correct
41 Correct 3 ms 2404 KB Output is correct
42 Correct 1 ms 2396 KB Output is correct
43 Correct 3 ms 2404 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 4 ms 2396 KB Output is correct
46 Correct 21 ms 4696 KB Output is correct
47 Correct 3 ms 4700 KB Output is correct
48 Correct 13 ms 4700 KB Output is correct
49 Correct 4 ms 4696 KB Output is correct
50 Correct 15 ms 4700 KB Output is correct
51 Execution timed out 4043 ms 6896 KB Time limit exceeded
52 Halted 0 ms 0 KB -