Submission #893411

#TimeUsernameProblemLanguageResultExecution timeMemory
893411ksujay2Council (JOI23_council)C++17
56 / 100
4027 ms8788 KiB
#include <bits/stdc++.h> using namespace std; const int BS = 2000; 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; auto dp = [&] () { for(int i = 0; i < (1 << M); i++) { for(int j = 0; j < M; j++) { if((i & (1 << j)) > 0) { D[i] = min(D[i], D[i ^ (1 << j)]); } } } for(int i = (1 << M) - 1; i >= 0; i--) { for(int j = 0; j < M; j++) { if((i & (1 << j)) == 0) { D[i] = min(D[i], D[i ^ (1 << j)] + 1); } } } }; for(int i = 0; i < N; i++) { if(i % BS == 0) { D = vector<int>(1 << M, INF); for(int j = 0; j < N; j++) { if(j < i || i + BS <= j) { D[A[j]] = 0; } } dp(); } 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...