Submission #919885

#TimeUsernameProblemLanguageResultExecution timeMemory
919885OAleksaCouncil (JOI23_council)C++14
33 / 100
4085 ms19292 KiB
#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<int, int> bst[1 << M];
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]++;
  			}
  		}
  	}
  	for (int i = 0;i < (1 << m);i++)
  		bst[i] = {i, i};
  	for (int i = 0;i < (1 << m);i++) {
  		for (int j = 1;j <= n;j++) {
  			int k = __builtin_popcount(a[j] & i);
  			if (k <= __builtin_popcount(bst[i].f & i)) {
  				bst[i].s = bst[i].f;
  				bst[i].f = a[j];
  			}
  			else if (k <= __builtin_popcount(bst[i].s & i))
  				bst[i].s = a[j];
  		}
  	}
  	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++;
  		}
  		if (bst[b].f == a[i])
  			ans += c - (__builtin_popcount(bst[b].s & b));
  		else
  			ans += c - (__builtin_popcount(bst[b].f & b));
  		cout << ans << '\n';
  	}
  }
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...