# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
783844 | YassineBenYounes | Council (JOI23_council) | C++17 | 4082 ms | 16400 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
typedef long long ll;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pbds tree<pair<ll, ll>, null_type, less<pair<ll,ll>>,rb_tree_tag, tree_order_statistics_node_update>
using namespace __gnu_pbds;
#define speed ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
////////////////////Only Clear Code//////////////////////////
void usaco_problem(){
freopen("milkvisits.in", "r", stdin);
freopen("milkvisits.out", "w", stdout);
}
void init(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}
const int mx = (1 << 20)+5;
const int LOG = 25;
const ll inf = 1e18;
const ll mod = 1e8;
int arr[mx];
int sum[25];
int freq[mx], cnt[mx];
int done[mx];
void run_case(){
int n, m;cin >> n >> m;
for(int i = 0; i < n;i++){
for(int j = 0;j < m;j++){
int a;cin >> a;
arr[i] += (1 << j) * a;
sum[j] += a;
}
freq[arr[i]]++;
}
for(int i = 0; i < (1 << m);i++){
for(int j = 0;j < m;j++){
if((1 << j) & i){
cnt[i]++;
}
}
}
memset(done, -1, sizeof done);
for(int i = 0; i < n;i++){
if(done[arr[i]] != -1){
cout << done[arr[i]] << endl;
continue;
}
int res = 0, ans = 0;
int x = 0;
for(int j = 0;j < m;j++){
bool p =(arr[i] & (1 << j));
sum[j] -= p;
if(sum[j] == n/2)x += (1 << j);
if(sum[j] >= n/2)res++;
}
//cout << res << endl;
for(int mask = 0; mask < (1 << m);mask++){
int k = x & mask;
int target = cnt[k];
//cout << mask << " " << target << endl;
if(mask == arr[i]){
if(freq[mask] >= 2){
ans = max(ans, res-target);
}
}
else if(freq[mask] >= 1){
ans = max(ans, res-target);
}
}
cout << ans << endl;
for(int j = 0;j < m;j++){
bool p =(arr[i] & (1 << j));
sum[j] += p;
}
done[arr[i]] = ans;
}
}
int32_t main(){
speed;
int t = 1;
//cin >> t;
while(t--){
run_case();
}
}
/*
NEVER GIVE UP!
DOING SMTHNG IS BETTER THAN DOING NTHNG!!!
Your Guide when stuck:
- Continue keyword only after reading the whole input
- Don't use memset with testcases
- Check for corner cases(n=1, n=0)
- Check where you declare n(Be careful of declaring it globally and in main)
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |