Submission #931883

#TimeUsernameProblemLanguageResultExecution timeMemory
931883alextodoranCouncil (JOI23_council)C++17
0 / 100
1 ms2396 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]; int dp[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]; } int sub = mask; while (true) { dp[sub] = 1; sub--; if (sub < 0) { break; } sub &= mask; } } for (int mask = 0; mask < (1 << M); mask++) { dp[mask] = __builtin_popcount(mask); } for (int j = 0; j < M; j++) { int bit = (1 << j); for (int mask = bit; mask < (1 << M); mask = ((mask + 1) | bit)) { dp[mask] = max(dp[mask], dp[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); } } cout << cnt_ok + dp[mask_bonus] << "\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...