답안 #1043721

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1043721 2024-08-04T14:47:24 Z juicy Council (JOI23_council) C++17
62 / 100
224 ms 21900 KB
// https://oj.uz/submission/767768 <3

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int N = 3e5 + 5, MAX = 1e9;
const array<int, 2> inf = {MAX, MAX};

int n, m;
int a[N], cnt[20];
array<array<int, 2>, 2> f[N], g[N];

void add(array<array<int, 2>, 2> &x, array<int, 2> y) {
  for (auto it : x) {
    if (it[1] == y[1]) {
      return;
    }
  }
  if (y[0] < x[0][0]) {
    x[1] = x[0];
    x[0] = y;
  } else {
    x[1] = min(x[1], y);
  }
}

void upd(array<array<int, 2>, 2> &x, array<array<int, 2>, 2> y) {
  for (auto it : y) {
    add(x, it);
  }
}

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  cin >> n >> m;
  for (int i = 0; i < (1 << m); ++i) {
    f[i] = g[i] = {inf, inf};
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < m; ++j) {
      int x; cin >> x;
      a[i] += x << j;
      cnt[j] += x;
    }
    add(f[a[i]], {__builtin_popcount(a[i]), i});
  }
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < (1 << m); ++j) {
      if (!(j >> i & 1)) {
        upd(f[j], f[j ^ (1 << i)]);
      }
    }
  }
  for (int i = 0; i < (1 << m); ++i) {
    int cnt = __builtin_popcount(i);
    for (auto [x, it] : f[i]) {
      add(g[i], {x - cnt, it});
    }
  }
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < (1 << m); ++j) {
      if (j >> i & 1) {
        upd(g[j], g[j ^ (1 << i)]);
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    int mask = (1 << m) - 1, res = 0;
    for (int j = 0; j < m; ++j) {
      int c = a[i] >> j & 1;
      cnt[j] -= c;
      if (cnt[j] > n / 2) {
        ++res;
      } else if (cnt[j] == n / 2) {
        mask ^= 1 << j;
        ++res;
      }
      cnt[j] += c;
    }
    for (auto [x, it] : g[mask]) {
      if (it != i) {
        res -= x;
        break;
      }
    }
    cout << res << "\n";
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Runtime error 11 ms 21900 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Runtime error 11 ms 21900 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 34 ms 6228 KB Output is correct
3 Correct 30 ms 6356 KB Output is correct
4 Correct 23 ms 5808 KB Output is correct
5 Correct 33 ms 6236 KB Output is correct
6 Correct 24 ms 5696 KB Output is correct
7 Correct 34 ms 6232 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 1 ms 4556 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 0 ms 4444 KB Output is correct
16 Correct 0 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 34 ms 6228 KB Output is correct
3 Correct 30 ms 6356 KB Output is correct
4 Correct 23 ms 5808 KB Output is correct
5 Correct 33 ms 6236 KB Output is correct
6 Correct 24 ms 5696 KB Output is correct
7 Correct 34 ms 6232 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 1 ms 4556 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 0 ms 4444 KB Output is correct
16 Correct 0 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 0 ms 4560 KB Output is correct
20 Correct 121 ms 10956 KB Output is correct
21 Correct 119 ms 10432 KB Output is correct
22 Correct 107 ms 10324 KB Output is correct
23 Correct 97 ms 11348 KB Output is correct
24 Correct 99 ms 11084 KB Output is correct
25 Correct 122 ms 10948 KB Output is correct
26 Correct 127 ms 11092 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4696 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 0 ms 4444 KB Output is correct
32 Correct 0 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 0 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 0 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 0 ms 4444 KB Output is correct
40 Correct 0 ms 4444 KB Output is correct
41 Correct 0 ms 4444 KB Output is correct
42 Correct 0 ms 4444 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 34 ms 6228 KB Output is correct
3 Correct 30 ms 6356 KB Output is correct
4 Correct 23 ms 5808 KB Output is correct
5 Correct 33 ms 6236 KB Output is correct
6 Correct 24 ms 5696 KB Output is correct
7 Correct 34 ms 6232 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 1 ms 4556 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 0 ms 4444 KB Output is correct
16 Correct 0 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 0 ms 4560 KB Output is correct
20 Correct 121 ms 10956 KB Output is correct
21 Correct 119 ms 10432 KB Output is correct
22 Correct 107 ms 10324 KB Output is correct
23 Correct 97 ms 11348 KB Output is correct
24 Correct 99 ms 11084 KB Output is correct
25 Correct 122 ms 10948 KB Output is correct
26 Correct 127 ms 11092 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4696 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 0 ms 4444 KB Output is correct
32 Correct 0 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 0 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 0 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 0 ms 4444 KB Output is correct
40 Correct 0 ms 4444 KB Output is correct
41 Correct 0 ms 4444 KB Output is correct
42 Correct 0 ms 4444 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 1 ms 4444 KB Output is correct
46 Correct 1 ms 4440 KB Output is correct
47 Correct 169 ms 15696 KB Output is correct
48 Correct 154 ms 12856 KB Output is correct
49 Correct 154 ms 12848 KB Output is correct
50 Correct 133 ms 15956 KB Output is correct
51 Correct 136 ms 15608 KB Output is correct
52 Correct 150 ms 15700 KB Output is correct
53 Correct 165 ms 15992 KB Output is correct
54 Correct 3 ms 6744 KB Output is correct
55 Correct 2 ms 6748 KB Output is correct
56 Correct 2 ms 6748 KB Output is correct
57 Correct 2 ms 6748 KB Output is correct
58 Correct 2 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 34 ms 6228 KB Output is correct
3 Correct 30 ms 6356 KB Output is correct
4 Correct 23 ms 5808 KB Output is correct
5 Correct 33 ms 6236 KB Output is correct
6 Correct 24 ms 5696 KB Output is correct
7 Correct 34 ms 6232 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 1 ms 4556 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 0 ms 4444 KB Output is correct
16 Correct 0 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 0 ms 4560 KB Output is correct
20 Correct 121 ms 10956 KB Output is correct
21 Correct 119 ms 10432 KB Output is correct
22 Correct 107 ms 10324 KB Output is correct
23 Correct 97 ms 11348 KB Output is correct
24 Correct 99 ms 11084 KB Output is correct
25 Correct 122 ms 10948 KB Output is correct
26 Correct 127 ms 11092 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4696 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 0 ms 4444 KB Output is correct
32 Correct 0 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 0 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 0 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 0 ms 4444 KB Output is correct
40 Correct 0 ms 4444 KB Output is correct
41 Correct 0 ms 4444 KB Output is correct
42 Correct 0 ms 4444 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 1 ms 4444 KB Output is correct
46 Correct 1 ms 4440 KB Output is correct
47 Correct 169 ms 15696 KB Output is correct
48 Correct 154 ms 12856 KB Output is correct
49 Correct 154 ms 12848 KB Output is correct
50 Correct 133 ms 15956 KB Output is correct
51 Correct 136 ms 15608 KB Output is correct
52 Correct 150 ms 15700 KB Output is correct
53 Correct 165 ms 15992 KB Output is correct
54 Correct 3 ms 6744 KB Output is correct
55 Correct 2 ms 6748 KB Output is correct
56 Correct 2 ms 6748 KB Output is correct
57 Correct 2 ms 6748 KB Output is correct
58 Correct 2 ms 6748 KB Output is correct
59 Correct 178 ms 17016 KB Output is correct
60 Correct 100 ms 12792 KB Output is correct
61 Correct 102 ms 13060 KB Output is correct
62 Correct 121 ms 13308 KB Output is correct
63 Correct 192 ms 16764 KB Output is correct
64 Correct 216 ms 19536 KB Output is correct
65 Correct 222 ms 19444 KB Output is correct
66 Correct 166 ms 19836 KB Output is correct
67 Correct 178 ms 19456 KB Output is correct
68 Correct 210 ms 19536 KB Output is correct
69 Correct 224 ms 19792 KB Output is correct
70 Correct 12 ms 8792 KB Output is correct
71 Correct 11 ms 8848 KB Output is correct
72 Correct 12 ms 8796 KB Output is correct
73 Correct 13 ms 8852 KB Output is correct
74 Correct 13 ms 8856 KB Output is correct
75 Correct 29 ms 8924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Runtime error 11 ms 21900 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -