Submission #889666

#TimeUsernameProblemLanguageResultExecution timeMemory
889666vjudge1Council (JOI23_council)C++14
41 / 100
4040 ms70996 KiB
/* author : abushbandit contest : --- */ #include "bits/stdc++.h" #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define int long long #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define ff first #define ss second #define pb push_back #define rep(i,s,f) for(int i = s;i < f;i++) #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #pragma GCC optimize("Ofast,no-stack-protector,fast-math",3) template <class type1> using ordered_multiset = tree <type1, null_type, less_equal <type1>, rb_tree_tag, tree_order_statistics_node_update>; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<pair<int,int>> vii; typedef pair<int,int> pii; const ll INF = 1e18; const ll MOD7 = 1e9 + 7; const ll MOD9 = 998244353; const ld PI = acos(-1.0); const int N = 1e5 + 6; template <class F, class _S> bool chmin(F &u, const _S &v){ bool flag = false; if ( u > v ){ u = v; flag |= true; } return flag; } template <class F, class _S> bool chmax(F &u, const _S &v){ bool flag = false; if ( u < v ){ u = v; flag |= true; } return flag; } int binpow (int a, int n) { int res = 1; while (n) { if (n & 1) res *= a; a *= a; n >>= 1; } return res; } void start_file(string file){ freopen((file + ".in").c_str(),"r",stdin); freopen((file + ".out").c_str(),"w",stdout); } void solve(int tc){ int n,m; cin >> n >> m; int a[n][m],s[m],b[n][m]; rep(i,0,n){ rep(j,0,m){ cin >> a[i][j]; b[i][j] = a[i][j]; } } rep(j,0,m){ int cnt = 0; rep(i,0,n){ cnt += a[i][j] > 0; } s[j] = cnt; // cout << s[j] << "\n"; } if(n <= 3000){ rep(i,0,n){ rep(j,0,m){ a[i][j] = b[i][j]; } } for(int i = 0;i < n;i++){ int ans = 0; for(int j = 0;j < n;j++){ if(i != j){ int cnt = 0; for(int k = 0;k < m;k++){ // cout << s[k] << " "; if(s[k] - ((a[i][k] == 1) + (a[j][k] == 1)) >= (n) / 2){ cnt++; } } // cout << "\n"; ans = max(ans,cnt); } } cout << ans << "\n"; } } else { int mp[N] {},l[n + 1] {}; rep(i,0,n){ int mask = 0; for(int j = 0;j < m;j++){ mask += (1 << j) * a[i][j]; } l[i] = mask; mp[mask]++; } int res[N] {}; for(int mask = 0;mask < (1 << m);mask++){ if(mp[mask] == 0){ continue; } int ans = 0; for(int msk = 0;msk < (1 << m);msk++){ if((mask == msk && mp[mask] < 2) || (mp[msk] == 0)){ continue; } int cnt = 0; for(int k = 0;k < m;k++){ int h = msk >> k & 1; int z = mask >> k & 1; if(s[k] - (h + z) >= n / 2){ cnt++; } } ans = max(ans,cnt); } res[mask] = ans; } rep(i,0,n){ cout << res[l[i]] << "\n"; } } } signed main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); // start_file(""); ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); int test_cases = 1; // cin >> test_cases ; for(int tc = 1;tc <= test_cases;++ tc){ solve(tc); } }

Compilation message (stderr)

council.cpp: In function 'void start_file(std::string)':
council.cpp:75:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |  freopen((file + ".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
council.cpp:76:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |  freopen((file + ".out").c_str(),"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...