# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
920007 |
2024-02-02T01:02:07 Z |
OAleksa |
Council (JOI23_council) |
C++14 |
|
47 ms |
43864 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
const int N = 3e5 + 69;
const int M = 21;
int a[N], cnt[M], n, m;
int t[M];
pair<pair<int, int>, pair<int, int>> bst[1030][1030];
int kurac[1030][1030];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
cin >> n >> m;
for (int i = 1;i <= n;i++) {
for (int j = 0;j < m;j++) {
int x;
cin >> x;
if (x > 0) {
a[i] += (1 << j);
cnt[j]++;
}
}
}
int k = (m + 1) / 2;
for (int i = 0;i < (1 << k);i++) {
for (int j = 0;j < (1 << k);j++) {
kurac[i][j] = __builtin_popcount(i & j);
bst[i][j] = {{(1 << m) - 1, m + 1}, {(1 << m) - 1, m + 1}};
}
}
for (int i = 0;i < (1 << k);i++) {
for (int j = 1;j <= n;j++) {
int pr = (a[j] & ((1 << (m - k)) - 1));
if (kurac[(a[j] >> (m - k))][i] < bst[pr][i].f.s) {
bst[pr][i].s = bst[pr][i].f;
bst[pr][i].f = {a[j], kurac[(a[j] >> (m - k))][i]};
}
else if (k < bst[pr][i].s.s)
bst[pr][i].s = {a[j], kurac[(a[j] >> (m - k))][i]};
}
}
//sufix duzine k, prefix duzine m - k
for (int i = 1;i <= n;i++) {
int b = 0, ans = 0, c = 0;
for (int j = 0;j < m;j++) {
t[j] = cnt[j];
if (a[i] & (1 << j))
t[j]--;
if (t[j] == n / 2) {
b += (1 << j);
c++;
}
else if (t[j] > n / 2)
ans++;
}
int suf = (b >> (m - k)), s = c;
int pr = (b & ((1 << (m - k)) - 1));
for (int j = 0;j < (1 << (m - k));j++) {
if (a[i] != bst[j][suf].f.f)
s = min(s, bst[j][suf].f.s + kurac[pr][j]);
else
s = min(s, bst[j][suf].s.s + kurac[pr][j]);
}
ans += c - s;
cout << ans << '\n';
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
8536 KB |
Output is correct |
3 |
Correct |
1 ms |
6488 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
10 ms |
43612 KB |
Output is correct |
6 |
Correct |
10 ms |
43608 KB |
Output is correct |
7 |
Correct |
9 ms |
43812 KB |
Output is correct |
8 |
Correct |
9 ms |
43612 KB |
Output is correct |
9 |
Correct |
12 ms |
43612 KB |
Output is correct |
10 |
Correct |
9 ms |
43864 KB |
Output is correct |
11 |
Correct |
10 ms |
43736 KB |
Output is correct |
12 |
Correct |
15 ms |
43608 KB |
Output is correct |
13 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
8536 KB |
Output is correct |
3 |
Correct |
1 ms |
6488 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
10 ms |
43612 KB |
Output is correct |
6 |
Correct |
10 ms |
43608 KB |
Output is correct |
7 |
Correct |
9 ms |
43812 KB |
Output is correct |
8 |
Correct |
9 ms |
43612 KB |
Output is correct |
9 |
Correct |
12 ms |
43612 KB |
Output is correct |
10 |
Correct |
9 ms |
43864 KB |
Output is correct |
11 |
Correct |
10 ms |
43736 KB |
Output is correct |
12 |
Correct |
15 ms |
43608 KB |
Output is correct |
13 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
41 ms |
5716 KB |
Output is correct |
3 |
Correct |
42 ms |
4972 KB |
Output is correct |
4 |
Correct |
32 ms |
5712 KB |
Output is correct |
5 |
Correct |
47 ms |
5712 KB |
Output is correct |
6 |
Incorrect |
31 ms |
5712 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
41 ms |
5716 KB |
Output is correct |
3 |
Correct |
42 ms |
4972 KB |
Output is correct |
4 |
Correct |
32 ms |
5712 KB |
Output is correct |
5 |
Correct |
47 ms |
5712 KB |
Output is correct |
6 |
Incorrect |
31 ms |
5712 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
41 ms |
5716 KB |
Output is correct |
3 |
Correct |
42 ms |
4972 KB |
Output is correct |
4 |
Correct |
32 ms |
5712 KB |
Output is correct |
5 |
Correct |
47 ms |
5712 KB |
Output is correct |
6 |
Incorrect |
31 ms |
5712 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
41 ms |
5716 KB |
Output is correct |
3 |
Correct |
42 ms |
4972 KB |
Output is correct |
4 |
Correct |
32 ms |
5712 KB |
Output is correct |
5 |
Correct |
47 ms |
5712 KB |
Output is correct |
6 |
Incorrect |
31 ms |
5712 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
8536 KB |
Output is correct |
3 |
Correct |
1 ms |
6488 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
10 ms |
43612 KB |
Output is correct |
6 |
Correct |
10 ms |
43608 KB |
Output is correct |
7 |
Correct |
9 ms |
43812 KB |
Output is correct |
8 |
Correct |
9 ms |
43612 KB |
Output is correct |
9 |
Correct |
12 ms |
43612 KB |
Output is correct |
10 |
Correct |
9 ms |
43864 KB |
Output is correct |
11 |
Correct |
10 ms |
43736 KB |
Output is correct |
12 |
Correct |
15 ms |
43608 KB |
Output is correct |
13 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |