Submission #889671

# Submission time Handle Problem Language Result Execution time Memory
889671 2023-12-20T04:57:41 Z vjudge1 Council (JOI23_council) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define ll long long
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define bc back()
#define ar array
#define vll vector<ll> 
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class _T>
bool chmin(_T &x, const _T &y){
    if(x>y){
        x=y;
        return true;
    }
    return false;
}
template <class _T>
bool chmax(_T &x, const _T &y){
    bool flag=false;
    if (x<y){
        x=y;flag|=true;
    }
    return flag;
}
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
void start(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const ll inf=2e18+7;
const ll mod=1e9+7;
const ll N=3e5+7;
const ld eps=1e-9;
ll a[N][23];
ll b[N];
ll mp[N];
void solve(){
	ll i,j;
	ll n,m;
	cin>>n>>m;
	ll cnt[m+5],sum=0;
	memset(cnt,0ll,sizeof(cnt));
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			cin>>a[i][j];
			if(a[i][j]){
				cnt[j]++;
				b[i]+=(1ll<<(j-1));
			}
		}
	}
	ll ans[n+5];
	memset(ans,0ll,sizeof(ans));
	if(n<=3000){
		for(j=1;j<=m;j++)if(cnt[j]>=n/2)sum++;
		for(i=1;i<=n;i++){
			for(j=i+1;j<=n;j++){
				ll x=sum;
				for(q=1;q<=m;q++){
					ll c=0;
					if(a[i][q])c++;
					if(a[j][q])c++;
					if(cnt[q]>=n/2 && cnt[q]-c<n/2)x--;
				}
				chmax(ans[i],x);
				chmax(ans[j],x);
			}
		}
		for(i=1;i<=n;i++){
			cout<<ans[i]<<endl;
		}
		return;
	}
	vector<vll> vv(N);
	vll v;
	for(i=1;i<=n;i++){
		if(mp[b[i]]==0)v.pb(b[i]);
		mp[b[i]]++;
		vv[b[i]].pb(i);
	}
	for(i=0;i<(ll)v.sz;i++){
		ll f=0,c=0;
		for(j=0;j<m;j++){
			if(v[i]&(1ll<<j)){
				if(cnt[j+1]-1==n/2)f+=(1ll<<j);
				if(cnt[j+1]-1>=n/2)c++;
			}else{
				if(cnt[j+1]==n/2)f+=(1ll<<j);
				if(cnt[j+1]>=n/2)c++;
			}
		}
		mp[v[i]]--;
		ll mn=25;
		for(j=0;j<(ll)v.sz;j++){
			if(mp[v[j]]==0)continue;
			mn=min(mn,(ll)__builtin_popcount(v[j]&f));
		}
		mp[v[i]]++;
		for(auto j : vv[v[i]]){
			ans[j]=c-mn;
		}
	}
	for(i=1;i<=n;i++)cout<<ans[i]<<endl;
}
signed main(){
	start();
    ll t=1;
	//cin>>t;
    while(t--) solve();
    return 0;
}
/*
1
6
5 4 3 2 1 0





*/

Compilation message

council.cpp: In function 'void solve()':
council.cpp:77:9: error: 'q' was not declared in this scope
   77 |     for(q=1;q<=m;q++){
      |         ^
council.cpp: In function 'void fre(std::string)':
council.cpp:42:27: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 | void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
council.cpp:42:64: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 | void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                                                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~