Submission #893391

#TimeUsernameProblemLanguageResultExecution timeMemory
893391ksujay2Council (JOI23_council)C++17
8 / 100
4072 ms1048576 KiB
#include <bits/stdc++.h> using namespace std; const int BS = 550; const int INF = 1e9; int main() { ios::sync_with_stdio(false), cin.tie(nullptr); int N, M; cin >> N >> M; vector<int> A(N); vector<int> cnt(M); for(int i = 0; i < N; i++) { for(int j = 0; j < M; j++) { int a; cin >> a; A[i] += a << j; cnt[j] += a; } } vector<int> D; for(int i = 0; i < N; i++) { if(i % BS == 0) { D = vector<int>(1 << M, INF); deque<int> q; for(int j = 0; j < N; j++) { if(j < i || i + BS <= j) { D[A[j]] = 0; q.push_back(A[j]); } } while(q.size() > 0) { int s = q.front(); q.pop_front(); for(int j = 0; j < M; j++) { if(D[s ^ (1 << j)] > D[s]) { if((s & (1 << j)) > 0) { D[s ^ (1 << j)] = D[s] + 1; q.push_back(s ^ (1 << j)); } else { D[s ^ (1 << j)] = D[s]; q.push_front(s ^ (1 << j)); } } } } } int v = (1 << M) - 1; int ans = 0; for(int j = 0; j < M; j++) { int c = (cnt[j] - ((A[i] & (1 << j)) > 0)); if(c == N / 2) { v ^= 1 << j; } if(c >= N / 2) ans++; } int best = D[v]; for(int j = i - (i % BS); j < (i - (i % BS) + BS) && j < N; j++) { if(j != i) { best = min(best, __popcount(A[j] ^ (A[j] & v))); } } cout << ans - best << '\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...