# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
741876 |
2023-05-15T03:19:17 Z |
pavement |
Council (JOI23_council) |
C++17 |
|
4000 ms |
33108 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
//~ #define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
#define g4(a) get<4>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using db = double;
using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using iii = tuple<int, int, int>;
using iiii = tuple<int, int, int, int>;
using iiiii = tuple<int, int, int, int, int>;
template<class key, class value = null_type, class cmp = less<key> >
using ordered_set = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
int N, M, X[300005], cnt[25];
bool b;
ii vec[(1 << 20) + 5][2], ans[(1 << 20) + 5][2];
void merge(ii a[], ii b[]) {
ii c[4];
c[0] = a[0];
c[1] = a[1];
c[2] = b[0];
c[3] = b[1];
ii best = mp((int)1e9, -1), sndbest = mp((int)1e9, -1);
for (int i = 0; i < 4; i++) {
best = min(best, c[i]);
}
for (int i = 0; i < 4; i++) {
if (c[i].second != best.second) sndbest = min(sndbest, c[i]);
}
a[0] = best;
a[1] = sndbest;
}
main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N >> M;
for (int i = 0; i < (1 << M); i++) {
for (int j = 0; j < 2; j++) {
vec[i][j] = ans[i][j] = mp((int)1e9, -1);
}
}
for (int i = 1; i <= N; i++) {
for (int j = 0; j < M; j++) {
cin >> b;
X[i] |= (1 << j) * b;
cnt[j] += b;
}
if (vec[X[i]][0].first == (int)1e9) {
vec[X[i]][0] = mp(__builtin_popcount(X[i]), i);
} else if (vec[X[i]][1].first == (int)1e9) {
vec[X[i]][1] = mp(__builtin_popcount(X[i]), i);
}
}
for (int m = 0; m < (1 << M); m++) {
for (int s = m; ; s = (s - 1) & m) {
merge(vec[s], vec[m]);
if (s == 0) break;
}
}
for (int m = 0; m < (1 << M); m++) {
for (int s = m; ; s = (s - 1) & m) {
// bm = s, k = m
ii cpy[2];
for (int i = 0; i < 2; i++) {
cpy[i] = mp(vec[s ^ m][i].first + __builtin_popcount(s) - __builtin_popcount(m), vec[s ^ m][i].second);
}
merge(ans[s], cpy);
if (s == 0) break;
}
}
for (int i = 1; i <= N; i++) {
int cur = 0, bm = 0;
for (int j = 0; j < M; j++) {
if (X[i] & (1 << j)) cnt[j]--;
}
for (int j = 0; j < M; j++) {
if (cnt[j] > N / 2) cur++;
else if (cnt[j] == N / 2) cur++, bm |= (1 << j);
}
for (auto el : ans[bm]) {
if (el.second != i) {
cur -= el.first;
break;
}
}
cout << cur << '\n';
for (int j = 0; j < M; j++) {
if (X[i] & (1 << j)) cnt[j]++;
}
}
}
Compilation message
council.cpp:49:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
49 | main() {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
19 ms |
472 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Execution timed out |
4086 ms |
33108 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
19 ms |
472 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Execution timed out |
4086 ms |
33108 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
63 ms |
2152 KB |
Output is correct |
3 |
Correct |
62 ms |
2044 KB |
Output is correct |
4 |
Correct |
42 ms |
1996 KB |
Output is correct |
5 |
Correct |
63 ms |
2004 KB |
Output is correct |
6 |
Correct |
41 ms |
2040 KB |
Output is correct |
7 |
Correct |
74 ms |
2004 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
63 ms |
2152 KB |
Output is correct |
3 |
Correct |
62 ms |
2044 KB |
Output is correct |
4 |
Correct |
42 ms |
1996 KB |
Output is correct |
5 |
Correct |
63 ms |
2004 KB |
Output is correct |
6 |
Correct |
41 ms |
2040 KB |
Output is correct |
7 |
Correct |
74 ms |
2004 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
239 ms |
2052 KB |
Output is correct |
21 |
Correct |
209 ms |
2016 KB |
Output is correct |
22 |
Correct |
212 ms |
2008 KB |
Output is correct |
23 |
Correct |
197 ms |
2324 KB |
Output is correct |
24 |
Correct |
204 ms |
2128 KB |
Output is correct |
25 |
Correct |
230 ms |
2016 KB |
Output is correct |
26 |
Correct |
254 ms |
2104 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
3 ms |
340 KB |
Output is correct |
36 |
Correct |
4 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
224 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
3 ms |
340 KB |
Output is correct |
45 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
63 ms |
2152 KB |
Output is correct |
3 |
Correct |
62 ms |
2044 KB |
Output is correct |
4 |
Correct |
42 ms |
1996 KB |
Output is correct |
5 |
Correct |
63 ms |
2004 KB |
Output is correct |
6 |
Correct |
41 ms |
2040 KB |
Output is correct |
7 |
Correct |
74 ms |
2004 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
239 ms |
2052 KB |
Output is correct |
21 |
Correct |
209 ms |
2016 KB |
Output is correct |
22 |
Correct |
212 ms |
2008 KB |
Output is correct |
23 |
Correct |
197 ms |
2324 KB |
Output is correct |
24 |
Correct |
204 ms |
2128 KB |
Output is correct |
25 |
Correct |
230 ms |
2016 KB |
Output is correct |
26 |
Correct |
254 ms |
2104 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
3 ms |
340 KB |
Output is correct |
36 |
Correct |
4 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
224 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
3 ms |
340 KB |
Output is correct |
45 |
Correct |
3 ms |
340 KB |
Output is correct |
46 |
Correct |
19 ms |
472 KB |
Output is correct |
47 |
Correct |
493 ms |
2540 KB |
Output is correct |
48 |
Correct |
357 ms |
2476 KB |
Output is correct |
49 |
Correct |
360 ms |
2392 KB |
Output is correct |
50 |
Correct |
387 ms |
2960 KB |
Output is correct |
51 |
Correct |
373 ms |
2552 KB |
Output is correct |
52 |
Correct |
472 ms |
2616 KB |
Output is correct |
53 |
Correct |
479 ms |
2856 KB |
Output is correct |
54 |
Correct |
131 ms |
852 KB |
Output is correct |
55 |
Correct |
152 ms |
852 KB |
Output is correct |
56 |
Correct |
163 ms |
852 KB |
Output is correct |
57 |
Correct |
152 ms |
852 KB |
Output is correct |
58 |
Correct |
169 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
63 ms |
2152 KB |
Output is correct |
3 |
Correct |
62 ms |
2044 KB |
Output is correct |
4 |
Correct |
42 ms |
1996 KB |
Output is correct |
5 |
Correct |
63 ms |
2004 KB |
Output is correct |
6 |
Correct |
41 ms |
2040 KB |
Output is correct |
7 |
Correct |
74 ms |
2004 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
239 ms |
2052 KB |
Output is correct |
21 |
Correct |
209 ms |
2016 KB |
Output is correct |
22 |
Correct |
212 ms |
2008 KB |
Output is correct |
23 |
Correct |
197 ms |
2324 KB |
Output is correct |
24 |
Correct |
204 ms |
2128 KB |
Output is correct |
25 |
Correct |
230 ms |
2016 KB |
Output is correct |
26 |
Correct |
254 ms |
2104 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
3 ms |
340 KB |
Output is correct |
36 |
Correct |
4 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
224 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
3 ms |
340 KB |
Output is correct |
45 |
Correct |
3 ms |
340 KB |
Output is correct |
46 |
Correct |
19 ms |
472 KB |
Output is correct |
47 |
Correct |
493 ms |
2540 KB |
Output is correct |
48 |
Correct |
357 ms |
2476 KB |
Output is correct |
49 |
Correct |
360 ms |
2392 KB |
Output is correct |
50 |
Correct |
387 ms |
2960 KB |
Output is correct |
51 |
Correct |
373 ms |
2552 KB |
Output is correct |
52 |
Correct |
472 ms |
2616 KB |
Output is correct |
53 |
Correct |
479 ms |
2856 KB |
Output is correct |
54 |
Correct |
131 ms |
852 KB |
Output is correct |
55 |
Correct |
152 ms |
852 KB |
Output is correct |
56 |
Correct |
163 ms |
852 KB |
Output is correct |
57 |
Correct |
152 ms |
852 KB |
Output is correct |
58 |
Correct |
169 ms |
852 KB |
Output is correct |
59 |
Correct |
1775 ms |
4424 KB |
Output is correct |
60 |
Execution timed out |
4049 ms |
4860 KB |
Time limit exceeded |
61 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
19 ms |
472 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Execution timed out |
4086 ms |
33108 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |