Submission #931899

#TimeUsernameProblemLanguageResultExecution timeMemory
931899alextodoranCouncil (JOI23_council)C++17
100 / 100
511 ms51964 KiB
/** _ _ __ _ _ _ _ _ _ |a ||t ||o d | |o | | __ _| | _ | __| _ | | __ |/_ | __ /__\ / _\| **/ #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N_MAX = 300000; const int M_MAX = 20; int N, M; bool vote[N_MAX][M_MAX]; int total[M_MAX]; struct Nirvana { int max1, max1i; int max2, max2i; }; Nirvana max (const Nirvana &a, const Nirvana &b) { Nirvana c; c.max1 = max(a.max1, b.max1); c.max1i = (c.max1 == a.max1 ? a.max1i : b.max1i); c.max2 = 0; c.max2i = 0; if (a.max1 > c.max2 && a.max1i != c.max1i) { c.max2 = a.max1; c.max2i = a.max1i; } if (b.max1 > c.max2 && b.max1i != c.max1i) { c.max2 = b.max1; c.max2i = b.max1i; } if (a.max2 > c.max2 && a.max2i != c.max1i) { c.max2 = a.max2; c.max2i = a.max2i; } if (b.max2 > c.max2 && b.max2i != c.max1i) { c.max2 = b.max2; c.max2i = b.max2i; } return c; } Nirvana dp1[1 << M_MAX]; Nirvana dp2[1 << M_MAX]; int main () { ios_base::sync_with_stdio(false); cin.tie(0); cin >> N >> M; for (int i = 0; i < N; i++) { int mask = 0; for (int j = 0; j < M; j++) { cin >> vote[i][j]; mask ^= (!vote[i][j] << j); total[j] += vote[i][j]; } dp1[mask] = max(dp1[mask], Nirvana{1, i, 0, 0}); } for (int j = 0; j < M; j++) { int bit = (1 << j); for (int mask = bit; mask < (1 << M); mask = ((mask + 1) | bit)) { dp1[mask ^ bit] = max(dp1[mask ^ bit], dp1[mask]); } } for (int mask = 0; mask < (1 << M); mask++) { int cnt = __builtin_popcount(mask); if (dp1[mask].max1 == 1) { dp2[mask].max1 = cnt; dp2[mask].max1i = dp1[mask].max1i; } if (dp1[mask].max2 == 1) { dp2[mask].max2 = cnt; dp2[mask].max2i = dp1[mask].max2i; } } for (int j = 0; j < M; j++) { int bit = (1 << j); for (int mask = bit; mask < (1 << M); mask = ((mask + 1) | bit)) { dp2[mask] = max(dp2[mask], dp2[mask ^ bit]); } } for (int i = 0; i < N; i++) { int cnt_ok = 0; int mask_bonus = 0; for (int j = 0; j < M; j++) { if ((total[j] - vote[i][j] - 1) * 2 > N - 2) { cnt_ok++; } else if ((total[j] - vote[i][j] - 0) * 2 > N - 2) { mask_bonus ^= (1 << j); } } Nirvana a = dp2[mask_bonus]; cout << cnt_ok + (a.max1i != i ? a.max1 : a.max2) << "\n"; } return 0; }
#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...