제출 #795092

#제출 시각아이디문제언어결과실행 시간메모리
795092vjudge1Council (JOI23_council)C++17
0 / 100
57 ms58660 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const int N = 3000000; const int M = 17; int n, m; int a[N]; int pr[(1 << M)][3]; vector<int> v[(1 << M)]; void add(int i) { int x = (((1 << m) - 1) ^ a[i]); if((int)v[x].size() > 1) return; for(int msk = x; msk > 0; msk = ((msk - 1) & x)) { if(v[msk].size() < 2 && (v[msk].empty() || v[msk][0] != 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]); } void print(int x) { for(int j = 0; j < m; j++) cout << ((x >> j) & 1); cout << '\n'; } vector<int> cnt(M); int main() { ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); cin >> n >> 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); } } } // 100100111010 // cout << pr[T][0] << ' ' << pr[T][1] << '\n'; // cout << func(T, pr[T][0]) << ' ' << func(T, pr[T][1]) << '\n'; 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); } // for(int j = 0; j < m; j++) // cout << ((msk >> j) & 1); // cout << ' ' << pr[msk][1] << '\n'; if(msk) { int k = pr[msk][(pr[msk][0] == i)]; ans -= __builtin_popcount(msk & a[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...