답안 #783835

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
783835 2023-07-15T11:17:24 Z YassineBenYounes Council (JOI23_council) C++17
0 / 100
325 ms 3240 KB
#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];

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]++;
            }
        }
    }
    for(int i = 0; i < n;i++){
        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 = 1; 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;
        }
    }
}

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

council.cpp: In function 'void usaco_problem()':
council.cpp:11:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     freopen("milkvisits.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
council.cpp:12:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     freopen("milkvisits.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
council.cpp: In function 'void init()':
council.cpp:18:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 | freopen("input.txt", "r", stdin);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
council.cpp:20:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 | freopen("output.txt", "w", stdout);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 322 ms 2300 KB Output is correct
3 Correct 322 ms 3192 KB Output is correct
4 Correct 306 ms 2644 KB Output is correct
5 Correct 325 ms 3240 KB Output is correct
6 Incorrect 307 ms 2644 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 322 ms 2300 KB Output is correct
3 Correct 322 ms 3192 KB Output is correct
4 Correct 306 ms 2644 KB Output is correct
5 Correct 325 ms 3240 KB Output is correct
6 Incorrect 307 ms 2644 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 322 ms 2300 KB Output is correct
3 Correct 322 ms 3192 KB Output is correct
4 Correct 306 ms 2644 KB Output is correct
5 Correct 325 ms 3240 KB Output is correct
6 Incorrect 307 ms 2644 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 322 ms 2300 KB Output is correct
3 Correct 322 ms 3192 KB Output is correct
4 Correct 306 ms 2644 KB Output is correct
5 Correct 325 ms 3240 KB Output is correct
6 Incorrect 307 ms 2644 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -