Submission #795105

#TimeUsernameProblemLanguageResultExecution timeMemory
795105vjudge1Council (JOI23_council)C++17
62 / 100
4046 ms46152 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const int N = 300000; const int M = 20; int n, m; int a[N]; int pr[(1 << M)][5]; vector<int> v[(1 << M)]; void add(int i) { int x = (((1 << m) - 1) ^ a[i]); if((int)v[x].size() == 2) return; for(int msk = x; msk > 0; msk = ((msk - 1) & x)) { if(v[msk].size() == 2) continue; if(v[msk].empty() || v[msk].back() != i) v[msk].push_back(i); } } int func(int msk, int i) { return __builtin_popcount((msk & a[i])); } int T = (1 << 0) + (1 << 3) + (1 << 6) + (1 << 7) + (1 << 8) + (1 << 10); void add1(int msk, int i) { // if(msk == T) cout << i << ' ' << func(msk, i) << '\n'; if(pr[msk][0] == i || pr[msk][1] == i) return; pr[msk][2] = i; if(func(msk, pr[msk][2]) < func(msk, pr[msk][1])) swap(pr[msk][1], pr[msk][2]); if(func(msk, pr[msk][1]) < func(msk, pr[msk][0])) swap(pr[msk][0], pr[msk][1]); if(func(msk, pr[msk][2]) < func(msk, pr[msk][1])) swap(pr[msk][1], pr[msk][2]); } void print(int x) { for(int j = 0; j < m; j++) cout << ((x >> j) & 1); cout << '\n'; } int main() { ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); cin >> n >> m; vector<int> cnt(m); for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { bool bt; cin >> bt; if(bt) { a[i] |= (1 << j); cnt[j]++; } } add(i); } for(int msk = 0; msk < (1 << m); msk++) { pr[msk][0] = 0; pr[msk][1] = 1; for(int x = msk; x > 0; x = ((x - 1) & msk)) { for(int c : v[x]) { add1(msk, c); } } } for(int i = 0; i < n; i++) { int msk = 0, ans = 0; for(int j = 0; j < m; j++) { int x = cnt[j] - (a[i] >> j & 1); if(x >= n / 2) ans++; if(x == n / 2) msk |= (1 << j); } int k = pr[msk][(pr[msk][0] == i)]; ans -= func(msk, k); cout << ans << '\n'; } }
#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...