Submission #783844

#TimeUsernameProblemLanguageResultExecution timeMemory
783844YassineBenYounesCouncil (JOI23_council)C++17
56 / 100
4082 ms16400 KiB
#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)

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);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...