Submission #893395

#TimeUsernameProblemLanguageResultExecution timeMemory
893395ksujay2Council (JOI23_council)C++17
8 / 100
1659 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); queue<int> q; for(int j = 0; j < N; j++) { if(j < i || i + BS <= j) { D[A[j]] = 0; q.push(A[j]); } } function<void(int)> dfs = [&] (int s) { 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(s ^ (1 << j)); } else { D[s ^ (1 << j)] = D[s]; dfs(s ^ (1 << j)); } } } }; while(q.size() > 0) { int s = q.front(); dfs(s); } } 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...