제출 #1261127

#제출 시각아이디문제언어결과실행 시간메모리
1261127anteknneCouncil (JOI23_council)C++20
56 / 100
4093 ms4404 KiB
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; #define pb push_back #define pii pair<int, int> #define pll pair<ll, ll> #define st first #define nd second #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> #define debug false const int MAXN = 300 * 1000 + 17; const int MAXM = 20; int ile[1 << MAXM]; int suma[MAXM]; int wyn[1 << MAXM]; int a[MAXN]; int n, m; void brut () { for (int i = 0; i < n; i ++) { int x = a[i]; for (int j = 0; j < m; j ++) { if (x % 2 == 1) { suma[j] --; } x /= 2; } for (int j = 0; j < n; j ++) { if ((i != j && ile[a[j]] >= 1) || (ile[a[j]] >= 2)) { int y = a[j]; int akt = 0; for (int k = 0; k < m; k ++) { int c = suma[k]; if (y % 2 == 1) { c --; } if (c >= n/2) { akt ++; } y /= 2; } wyn[i] = max(wyn[i], akt); } } x = a[i]; for (int j = 0; j < m; j ++) { if (x % 2 == 1) { suma[j] ++; } x /= 2; } } for (int i = 0; i < n; i ++) { cout << wyn[i] << "\n"; } } int get_int() { int x = 0; char c = getchar(); for(;(c < '0' || c > '9'); c = getchar()); for(;(c >= '0' && c <= '9') ; c = getchar()) { x = 10 * x + (c - '0'); } return x; } int main () { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); n = get_int(); m = get_int(); for (int i = 0; i < n; i ++) { int x = 0, y; for (int j = 0; j < m; j ++) { y = get_int(); x += (y * (1 << j)); if (y) { suma[j] ++; } } a[i] = x; ile[x] ++; } if (n <= 3 * 1000) { brut(); return 0; } for (int i = 0; i < (1 << m); i ++) { int x = i; for (int j = 0; j < m; j ++) { if (x % 2 == 1) { suma[j] --; } x /= 2; } for (int j = 0; j < (1 << m); j ++) { if ((i != j && ile[j] >= 1) || (ile[j] >= 2)) { int y = j; int akt = 0; for (int k = 0; k < m; k ++) { int c = suma[k]; if (y % 2 == 1) { c --; } if (c >= n/2) { akt ++; } y /= 2; } wyn[i] = max(wyn[i], akt); } } x = i; for (int j = 0; j < m; j ++) { if (x % 2 == 1) { suma[j] ++; } x /= 2; } } for (int i = 0; i < n; i ++) { cout << wyn[a[i]] << "\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...