QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#765628 | #6336. Council | KiharaTouma | 0 | 268ms | 34884kb | C++23 | 2.1kb | 2024-11-20 14:51:31 | 2024-11-20 14:51:31 |
Judging History
answer
//qoj6336
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int n, m, a[25][N], sum[25], v[N];
pair<int, int> f[N], g[N];
bool upd(int x, pair<int, int> y){
if((f[x] > y || (f[x] == y && g[x] > y)) && f[x].second != y.second){
g[x] = f[x];
f[x] = y;
return 1;
} else if(g[x] > y && f[x].second != y.second){
g[x] = y;
return 1;
}
return 0;
}
int main(){
for(int i = 0; i < N; ++ i){
f[i].first = g[i].first = 2e9;
}
scanf("%d%d", &n, &m);
queue<int> q;
for(int i = 1; i <= n; ++ i){
for(int j = 1; j <= m; ++ j){
scanf("%d", &a[j][i]);
sum[j] += a[j][i];
v[i] |= (1 - a[j][i]) << j - 1;
}
upd(v[i], make_pair(0, i));
q.push(v[i]);
}
while(!q.empty()){
int x = q.front();
q.pop();
for(int i = 0; i < m; ++ i){
int v = 1 + (1 - ((x >> i) & 1)) * 100;
if(upd(x^(1<<i), make_pair(f[x].first+v, f[x].second))){
q.push(x ^ (1 << i));
} else if(upd(x^(1<<i), make_pair(g[x].first+v, g[x].second))){
q.push(x ^ (1 << i));
}
}
}
for(int i = 1; i <= n; ++ i){
int val = 0, cnt = 0;
for(int j = 1; j <= m; ++ j){
if(sum[j] - a[j][i] == n / 2){
val |= 1 << j - 1;
} else if(sum[j] - a[j][i] > n / 2){
++ cnt;
}
}
int mx = 0;
if(f[val].second == i){
// printf("%d ", g[val].second);
mx = val & v[g[val].second];
} else {
// printf("%d ", f[val].second);
mx = val & v[f[val].second];
}
mx = __builtin_popcount(mx);
for(int j = 1; j <= n; ++ j){
if(j != i){
mx = max(mx, __builtin_popcount(val & v[j]));
}
}
// printf("%d %d %d\n", cnt, mx, val);
// printf("%d %d %d\n", val, f[val].second, f[val].first);
printf("%d\n", mx + cnt);
}
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: 268ms
memory: 34884kb
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:
1 1 0 0 1 1 1 0 0 1 1 1 1 1 1 1 0 1 1 0 0 0 0 1 0 0 1 1 0 0 0 1 0 0 0 1 0 0
result:
wrong answer 1st numbers differ - expected: '18', found: '1'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Time Limit Exceeded
Test #53:
score: 0
Time Limit Exceeded
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:
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
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%