QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#111932#6336. CouncilScintilla0 185ms41000kbC++142.5kb2023-06-09 10:34:482023-06-09 10:34:49

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-09 10:34:49]
  • 评测
  • 测评结果:0
  • 用时:185ms
  • 内存:41000kb
  • [2023-06-09 10:34:48]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define rep(i, s, e) for (int i = s; i <= e; ++i)
#define drep(i, s, e) for (int i = s; i >= e; --i)
#define file(a) freopen(#a".in", "r", stdin), freopen(#a".out", "w", stdout)
#define pv(a) cout << #a << " = " << a << endl
#define pa(a, l, r) cout << #a " : "; rep(_, l, r) cout << a[_] << ' '; cout << endl

using pii = pair <int, int>;

const int inf = 0x3f3f3f3f;

const int N = 2e5 + 10;
const int M = 20;

int read() {
  int x = 0, f = 1; char c = getchar();
  for (; c < '0' || c > '9'; c = getchar()) if (c == '-') f = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48;
  return x * f;
}

int n, m, a[N], cnt[M];
bool tag[1 << M];
struct node {
  pii x, y;
  node() { x = y = mp(inf, -1); }
  node(pii _x, pii _y) { x = _x, y = _y; }
  node nxt() {
    return node(mp(x.first + 1, x.second), mp(y.first + 1, y.second));
  }
} f[1 << M], d[1 << M];

bool add(node &u, pii v) {
  if (v.second == u.x.second) {
    if (v < u.x) return u.x = v, true;
    return false;
  }
  else if (v.second == u.y.second) {
    if (v < u.y) {
      u.y = v;
      if (u.y < u.x) swap(u.x, u.y);
      return true;
    }
    return false;
  }
  else {
    if (v < u.x) return u.y = u.x, u.x = v, true;
    else if (v < u.y) return u.y = v, true;
    return false;
  }
}

bool add(node &u, node v) {
  bool flag = add(u, v.x);
  flag |= add(u, v.y);
  return flag;
}

int main() {
  n = read(), m = read();
  rep(i, 1, n) {
    rep(j, 0, m - 1) {
      a[i] |= read() << j;
      cnt[j] += a[i] >> j & 1;
    }
    add(f[a[i]], mp(0, a[i]));
  }
  for (int k = 1; k < 1 << m; k <<= 1) {
    for (int i = 0; i < 1 << m; i += k << 1) {
      for (int j = 0; j < k; ++ j) {
        add(f[i + j + k], f[i + j]);
      }
    }
  }
  auto bfs = [&]() {
    queue <int> q;
    rep(s, 0, (1 << m) - 1) {
      d[s] = f[((1 << m) - 1) ^ s], q.push(s), tag[s] = true;
    }
    while (q.size()) {
      int s = q.front(); q.pop(), tag[s] = false;
      rep(i, 0, m - 1) if (~s >> i & 1) {
        int t = s | (1 << i);
        if (add(d[t], d[s].nxt()) && !tag[t]) q.push(t), tag[t] = true;
      }
    }
  } ;
  bfs();
  rep(i, 1, n) {
    int ans = 0, s = 0;
    rep(j, 0, m - 1) {
      int x = cnt[j] - (a[i] >> j & 1);
      ans += x >= n / 2, s |= (x == n / 2) << j;
    }
    printf("%d\n", ans - (d[s].x.second == a[i] ? d[s].y.first : d[s].x.first));
  }
  return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 8
Accepted
time: 185ms
memory: 40948kb

input:

38 20
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1
0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 1 1 1 1 1 1 ...

output:

18
18
1
1
18
18
18
1
1
18
18
18
18
18
18
18
1
18
18
1
18
1
1
18
1
1
18
18
1
1
1
18
1
1
1
18
1
1

result:

ok 38 numbers

Test #2:

score: -8
Wrong Answer
time: 171ms
memory: 41000kb

input:

300 20
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1...

output:

-1061109547
-1061109547
-1061109547
-1061109547
-1061109547
-1061109547
-1061109547
-1061109547
-1061109547
-1061109547
-1061109547
-1061109547
-1061109547
-1061109547
-1061109547
-1061109547
-1061109547
-1061109547
-1061109547
-1061109547
-1061109547
-1061109547
-1061109547
-1061109547
-1061109547
...

result:

wrong answer 1st numbers differ - expected: '20', found: '-1061109547'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Runtime Error

Test #53:

score: 0
Runtime Error

input:

300000 2
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1...

output:


result:


Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #5:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

0%