# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
985368 |
2024-05-17T17:02:30 Z |
vjudge2 |
Council (JOI23_council) |
C++17 |
|
4000 ms |
57948 KB |
#include <bits/stdc++.h>
using namespace std;
void update(vector<pair<int, int>>& a, vector<pair<int, int>>& b) {
vector<pair<int, int>> u;
set<int> occ;
// for (int i = 0; i < 2; i++) cout << a[i].first << ' ' << a[i].second << '\n';
// for (int i = 0; i < 2; i++) cout << b[i].first << ' ' << b[i].second << '\n';
for (int i = 0; i < 2; i++) {
// if (!occ.count(a[i]) && a[i].first != -1) {
u.push_back(a[i]);
// occ.insert(a[i]);
// }
// if (!occ.count(b[i]) && b[i].first != -1) {
u.push_back(b[i]);
// occ.insert(b[i]);
// }
}
sort(u.begin(), u.end(), [] (pair<int, int> x, pair<int, int> y) {
return x.first > y.first;
});
vector<pair<int, int>> v;
for (int i = 0; i < u.size(); i++) {
if (!occ.count(u[i].second) && u[i].first != -1) {
v.push_back(u[i]);
occ.insert(u[i].second);
}
}
while ((int) v.size() > 2) v.pop_back();
while ((int) v.size() < 2) v.push_back({-1, -1});
a = v;
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> a(n, 0), freq(m, 0), b(n, 0);
vector<vector<pair<int, int>>> dp(1 << m, vector<pair<int, int>> (2, {-1, -1}));
for (int i = 0; i < n; i++) {
int x;
for (int j = 0; j < m; j++) {
cin >> x;
a[i] += (x << j);
b[i] += ((1 - x) << j);
if (x) freq[j]++;
}
// bitset<6> bs(b[i]);
// cout << bs.to_string() << '\n';
vector<pair<int, int>> t = {{__builtin_popcount(b[i]), i}, {-1, -1}};
update(dp[b[i]], t);
}
// 4 6
// 1 1 0 0 1 1
// 1 0 1 1 1 1
// 0 0 0 0 0 1
// 0 1 1 1 0 0
// max(popcount(b[sth] & s))..
for (int i = (1 << m) - 1; i >= 0; i--) {
for (int j = 0; j < m; j++) {
if (i & (1 << j)) {
int k = (i ^ (1 << j));
vector<pair<int, int>> t = dp[i];
for (auto& [x, y] : t) if (x != -1) x--;
update(dp[k], t);
}
}
}
// for (int i = 0; i < (1 << m); i++) {
// bitset<6> bs(i);
// cout << bs.to_string() << '\n';
// cout << dp[i][0].first << ' ' << dp[i][1].first << '\n';
// }
for (int i = 0; i < (1 << m); i++) {
for (int j = 0; j < m; j++) {
if (i & (1 << j)) {
int k = (i ^ (1 << j));
// if (i == 23) cout << "debug: " << dp[i][0].first << ' ' << dp[i][1].first << ' ' << dp[k][0].first << ' ' << dp[k][1].first << '\n';
update(dp[i], dp[k]);
// if (i == 23) cout << "debug: " << dp[i][0].first << ' ' << dp[i][1].first << '\n';
}
}
// bitset<6> bs(i);
// cout << bs.to_string() << '\n';
// cout << dp[i][0].first << ' ' << dp[i][1].first << '\n';
}
for (int i = 0; i < n; i++) {
int ans = 0, sub = 0;
for (int j = 0; j < m; j++) {
int cnter = freq[j];
if (a[i] & (1 << j)) cnter--;
if (cnter > n / 2) ans++;
else if (cnter == n / 2) {
sub += (1 << j);
// cout << "crit: " << j << '\n';
}
}
// cout << ans << '\n';
// cout << dp[sub][0].first << ' ' << dp[sub][0].second << '\n';
// cout << dp[sub][1].first << ' ' << dp[sub][1].second << '\n';
if (i == dp[sub][0].second) cout << ans + dp[sub][1].first << '\n';
else cout << ans + dp[sub][0].first << '\n';
}
}
Compilation message
council.cpp: In function 'void update(std::vector<std::pair<int, int> >&, std::vector<std::pair<int, int> >&)':
council.cpp:23:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for (int i = 0; i < u.size(); i++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
9 ms |
680 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
3803 ms |
57948 KB |
Output is correct |
6 |
Correct |
3264 ms |
57688 KB |
Output is correct |
7 |
Correct |
3549 ms |
57692 KB |
Output is correct |
8 |
Correct |
3738 ms |
57860 KB |
Output is correct |
9 |
Execution timed out |
4035 ms |
57680 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
9 ms |
680 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
3803 ms |
57948 KB |
Output is correct |
6 |
Correct |
3264 ms |
57688 KB |
Output is correct |
7 |
Correct |
3549 ms |
57692 KB |
Output is correct |
8 |
Correct |
3738 ms |
57860 KB |
Output is correct |
9 |
Execution timed out |
4035 ms |
57680 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
115 ms |
4460 KB |
Output is correct |
3 |
Correct |
117 ms |
4432 KB |
Output is correct |
4 |
Correct |
110 ms |
3932 KB |
Output is correct |
5 |
Correct |
121 ms |
4348 KB |
Output is correct |
6 |
Correct |
108 ms |
3804 KB |
Output is correct |
7 |
Correct |
125 ms |
4696 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
115 ms |
4460 KB |
Output is correct |
3 |
Correct |
117 ms |
4432 KB |
Output is correct |
4 |
Correct |
110 ms |
3932 KB |
Output is correct |
5 |
Correct |
121 ms |
4348 KB |
Output is correct |
6 |
Correct |
108 ms |
3804 KB |
Output is correct |
7 |
Correct |
125 ms |
4696 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
600 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
600 KB |
Output is correct |
20 |
Correct |
238 ms |
9500 KB |
Output is correct |
21 |
Correct |
250 ms |
8692 KB |
Output is correct |
22 |
Correct |
224 ms |
8576 KB |
Output is correct |
23 |
Correct |
224 ms |
9372 KB |
Output is correct |
24 |
Correct |
206 ms |
9116 KB |
Output is correct |
25 |
Correct |
235 ms |
9304 KB |
Output is correct |
26 |
Correct |
241 ms |
9108 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
504 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
456 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
2 ms |
348 KB |
Output is correct |
36 |
Correct |
3 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
344 KB |
Output is correct |
44 |
Correct |
3 ms |
348 KB |
Output is correct |
45 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
115 ms |
4460 KB |
Output is correct |
3 |
Correct |
117 ms |
4432 KB |
Output is correct |
4 |
Correct |
110 ms |
3932 KB |
Output is correct |
5 |
Correct |
121 ms |
4348 KB |
Output is correct |
6 |
Correct |
108 ms |
3804 KB |
Output is correct |
7 |
Correct |
125 ms |
4696 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
600 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
600 KB |
Output is correct |
20 |
Correct |
238 ms |
9500 KB |
Output is correct |
21 |
Correct |
250 ms |
8692 KB |
Output is correct |
22 |
Correct |
224 ms |
8576 KB |
Output is correct |
23 |
Correct |
224 ms |
9372 KB |
Output is correct |
24 |
Correct |
206 ms |
9116 KB |
Output is correct |
25 |
Correct |
235 ms |
9304 KB |
Output is correct |
26 |
Correct |
241 ms |
9108 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
504 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
456 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
2 ms |
348 KB |
Output is correct |
36 |
Correct |
3 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
344 KB |
Output is correct |
44 |
Correct |
3 ms |
348 KB |
Output is correct |
45 |
Correct |
3 ms |
348 KB |
Output is correct |
46 |
Correct |
9 ms |
604 KB |
Output is correct |
47 |
Correct |
348 ms |
12496 KB |
Output is correct |
48 |
Correct |
302 ms |
11308 KB |
Output is correct |
49 |
Correct |
310 ms |
11300 KB |
Output is correct |
50 |
Correct |
299 ms |
12776 KB |
Output is correct |
51 |
Correct |
290 ms |
12432 KB |
Output is correct |
52 |
Correct |
385 ms |
12268 KB |
Output is correct |
53 |
Correct |
367 ms |
12588 KB |
Output is correct |
54 |
Correct |
46 ms |
1116 KB |
Output is correct |
55 |
Correct |
39 ms |
1116 KB |
Output is correct |
56 |
Correct |
43 ms |
1116 KB |
Output is correct |
57 |
Correct |
39 ms |
1116 KB |
Output is correct |
58 |
Correct |
46 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
115 ms |
4460 KB |
Output is correct |
3 |
Correct |
117 ms |
4432 KB |
Output is correct |
4 |
Correct |
110 ms |
3932 KB |
Output is correct |
5 |
Correct |
121 ms |
4348 KB |
Output is correct |
6 |
Correct |
108 ms |
3804 KB |
Output is correct |
7 |
Correct |
125 ms |
4696 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
600 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
600 KB |
Output is correct |
20 |
Correct |
238 ms |
9500 KB |
Output is correct |
21 |
Correct |
250 ms |
8692 KB |
Output is correct |
22 |
Correct |
224 ms |
8576 KB |
Output is correct |
23 |
Correct |
224 ms |
9372 KB |
Output is correct |
24 |
Correct |
206 ms |
9116 KB |
Output is correct |
25 |
Correct |
235 ms |
9304 KB |
Output is correct |
26 |
Correct |
241 ms |
9108 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
504 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
456 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
2 ms |
348 KB |
Output is correct |
36 |
Correct |
3 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
344 KB |
Output is correct |
44 |
Correct |
3 ms |
348 KB |
Output is correct |
45 |
Correct |
3 ms |
348 KB |
Output is correct |
46 |
Correct |
9 ms |
604 KB |
Output is correct |
47 |
Correct |
348 ms |
12496 KB |
Output is correct |
48 |
Correct |
302 ms |
11308 KB |
Output is correct |
49 |
Correct |
310 ms |
11300 KB |
Output is correct |
50 |
Correct |
299 ms |
12776 KB |
Output is correct |
51 |
Correct |
290 ms |
12432 KB |
Output is correct |
52 |
Correct |
385 ms |
12268 KB |
Output is correct |
53 |
Correct |
367 ms |
12588 KB |
Output is correct |
54 |
Correct |
46 ms |
1116 KB |
Output is correct |
55 |
Correct |
39 ms |
1116 KB |
Output is correct |
56 |
Correct |
43 ms |
1116 KB |
Output is correct |
57 |
Correct |
39 ms |
1116 KB |
Output is correct |
58 |
Correct |
46 ms |
1116 KB |
Output is correct |
59 |
Correct |
554 ms |
16560 KB |
Output is correct |
60 |
Correct |
736 ms |
12620 KB |
Output is correct |
61 |
Correct |
794 ms |
12944 KB |
Output is correct |
62 |
Correct |
783 ms |
13120 KB |
Output is correct |
63 |
Correct |
603 ms |
16300 KB |
Output is correct |
64 |
Correct |
911 ms |
20476 KB |
Output is correct |
65 |
Correct |
900 ms |
20496 KB |
Output is correct |
66 |
Correct |
699 ms |
20740 KB |
Output is correct |
67 |
Correct |
668 ms |
20352 KB |
Output is correct |
68 |
Correct |
933 ms |
20568 KB |
Output is correct |
69 |
Correct |
968 ms |
20744 KB |
Output is correct |
70 |
Correct |
421 ms |
7516 KB |
Output is correct |
71 |
Correct |
361 ms |
7512 KB |
Output is correct |
72 |
Correct |
395 ms |
7516 KB |
Output is correct |
73 |
Correct |
365 ms |
7516 KB |
Output is correct |
74 |
Correct |
386 ms |
7516 KB |
Output is correct |
75 |
Correct |
528 ms |
7768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
9 ms |
680 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
3803 ms |
57948 KB |
Output is correct |
6 |
Correct |
3264 ms |
57688 KB |
Output is correct |
7 |
Correct |
3549 ms |
57692 KB |
Output is correct |
8 |
Correct |
3738 ms |
57860 KB |
Output is correct |
9 |
Execution timed out |
4035 ms |
57680 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |