Submission #935200

#TimeUsernameProblemLanguageResultExecution timeMemory
935200tvladm2009Council (JOI23_council)C++17
33 / 100
4058 ms12224 KiB
#include <iostream> #include <complex> #include <vector> #include <string> #include <algorithm> #include <cstdio> #include <numeric> #include <cstring> #include <ctime> #include <cstdlib> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <list> #include <cmath> #include <bitset> #include <cassert> #include <queue> #include <stack> #include <deque> #include <random> using namespace std; template<typename T1, typename T2> inline void chkmin(T1 &a, T2 b) {if (a > b) a = b;} template<typename T1, typename T2> inline void chkmax(T1 &a, T2 b) {if (a < b) a = b;} #define files(FILENAME) read(FILENAME); write(FILENAME) #define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin) #define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout) #define all(c) (c).begin(), (c).end() #define sz(c) (int)(c).size() #define left left228 #define right right228 #define y1 y1228 #define mp make_pair #define pb push_back #define y2 y2228 #define rank rank228 using ll = long long; using ld = long double; const string FILENAME = "input"; const int MAXN = 300228; const int MAXM = 20 + 7; int n, m; int a[MAXN], cnt[MAXM]; pair<int, int> best[1 << 20]; int get_best(int mask, int i) { if (best[mask].first == i) { return __builtin_popcount(a[best[mask].second] & mask); } return __builtin_popcount(a[best[mask].first] & mask); } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); //read(FILENAME); cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 0; j < m; j++) { int x; cin >> x; if (x == 1) { a[i] |= (1 << j); cnt[j]++; } } } // asta merge cu sos for (int mask = 0; mask < (1 << m); mask++) { pair<int, int> cost = mp(m + 1, m + 1); best[mask] = mp(-1, -1); for (int i = 1; i <= n; i++) { if (__builtin_popcount(mask & a[i]) <= cost.first) { cost.second = cost.first; cost.first = __builtin_popcount(mask & a[i]); best[mask].second = best[mask].first; best[mask].first = i; } else if (__builtin_popcount(mask & a[i]) <= cost.second) { cost.second = __builtin_popcount(mask & a[i]); best[mask].second = i; } } } for (int i = 1; i <= n; i++) { vector<int> critic; int mask = 0; int sol = 0; for (int j = 0; j < m; j++) { int aux = cnt[j]; if (a[i] & (1 << j)) { aux--; } if (aux == n / 2) { critic.pb(j); mask |= (1 << j); } else if (aux > n / 2) { sol++; } } sol += sz(critic) - get_best(mask, i); cout << sol << '\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...