QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#111938 | #6336. Council | Scintilla | 6 | 167ms | 40916kb | C++14 | 2.5kb | 2023-06-09 10:39:06 | 2023-06-09 10:39:09 |
Judging History
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 = 3e5 + 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, 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;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 167ms
memory: 40916kb
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 19 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:
wrong answer 5th numbers differ - expected: '18', found: '19'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 6
Accepted
Test #53:
score: 6
Accepted
time: 21ms
memory: 37460kb
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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 0 1 1 1 0 0 0 1 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 1 0 0 1 ...
result:
ok 300000 numbers
Test #58:
score: 0
Accepted
time: 23ms
memory: 37564kb
input:
300000 2 0 0 0 0 1 0 0 1 0 0 1 1 1 0 0 1 1 0 1 0 0 1 1 1 0 0 0 1 0 0 1 1 1 1 0 0 0 1 1 1 0 1 0 0 0 0 1 1 1 0 1 0 1 0 0 0 1 1 0 0 0 0 1 1 1 0 1 1 0 0 0 1 0 1 1 1 1 1 0 1 1 0 0 1 0 0 0 1 1 1 0 1 1 0 0 1 1 0 1 1 0 0 0 1 1 1 1 0 0 0 1 0 0 0 1 1 1 0 1 0 1 0 0 1 0 0 1 0 1 1 0 1 1 0 0 0 0 0 0 0 1 1 0 1 0 1...
output:
2 2 2 1 2 1 2 1 2 2 1 1 2 1 2 1 1 2 1 1 1 2 2 1 2 2 2 2 1 2 2 1 2 1 2 1 1 1 1 1 2 1 2 1 1 1 2 1 2 1 2 1 1 2 2 2 2 1 2 2 2 1 2 2 1 1 2 2 2 2 1 1 1 1 1 2 1 2 1 2 1 2 2 1 1 2 2 2 2 1 1 1 2 1 2 2 2 1 1 2 1 2 1 1 1 2 2 2 1 1 2 2 2 2 1 2 1 2 1 1 2 2 2 1 2 1 1 1 1 2 1 2 1 2 1 1 1 1 1 1 2 2 2 2 2 2 1 1 1 2 ...
result:
ok 300000 numbers
Subtask #4:
score: 0
Wrong Answer
Dependency #3:
100%
Accepted
Test #59:
score: 0
Wrong Answer
time: 52ms
memory: 37556kb
input:
299999 10 0 1 1 1 0 0 1 0 1 0 1 0 1 0 1 0 0 0 1 1 0 0 1 0 1 1 1 0 0 1 1 0 1 1 0 1 0 0 0 1 0 0 1 0 1 1 0 0 1 1 0 0 0 1 0 1 0 1 1 1 0 1 1 0 0 0 1 1 0 1 0 1 1 1 1 0 0 0 1 0 1 1 0 1 0 0 0 1 1 0 1 1 0 1 1 0 0 0 1 0 1 0 1 1 0 0 0 1 0 1 1 1 1 1 0 0 1 0 0 0 1 0 0 0 1 0 1 0 1 1 0 0 0 1 0 0 1 1 1 1 1 1 1 0 0 ...
output:
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 ...
result:
wrong answer 242396th numbers differ - expected: '5', found: '10'
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Skipped
Dependency #1:
0%