Submission #1005852

# Submission time Handle Problem Language Result Execution time Memory
1005852 2024-06-23T07:07:14 Z pcc Council (JOI23_council) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt,sse4")
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>


const int mxn = 3e5+10;
const int B = 20;
short ans[1<<B];
int arr[mxn];
short dp[1<<B];
bitset<(1<<B)> done;
//int dp[1<<(10)][1<<(10)];//left = l,min of popcnt(right & r)
int mask[mxn];
int cnt[B];
int N,M;
short sh[mxn];
int rmask;
int tl,tr;

int pull(int tar){
	int re = B+1;
	for(int i = 0;i<(1<<tl);i++){
		//int tmp = __builtin_popcount((i<<tr)&tar)+dp[i][tar&rmask];
		int tmp = __builtin_popcount((i<<tr)&tar)+dp[(i<<tr)|(tar&rmask)];
		re = min(re,tmp);
	}
	return re;
}

void push(int now){
	if(done[now])return;
	done[now] = true;
	for(int i = 0;i<(1<<tr);i++){
		int tmp = __builtin_popcount(i&now);
		dp[((now>>tr)<<tr)|i] = min(dp[((now>>tr)<<tr)|i],tmp);
		//dp[now>>tr][i] = min(dp[now>>tr][i],tmp);
	}
	return;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>N>>M;
	tl = M>>1,tr = M-tl;
	rmask = (1<<tr)-1;
	memset(ans,-1,sizeof(ans));
	for(int i = 0;i<N;i++){
		for(int j = 0;j<M;j++){
			int k;
			cin>>k;
			if(k)arr[i] |= 1<<j,cnt[j]++;
		}
		ans[i] = B+1;
	}
	for(int i = 0;i<N;i++){
		for(int j = 0;j<M;j++){
			if(arr[i]&(1<<j))cnt[j]--;
			if(cnt[j]>=N/2)sh[i]++;
			if(cnt[j] == N/2)mask[i]|=1<<j;
			if(arr[i]&(1<<j))cnt[j]++;
		}
	}
	fill(dp,dp+(1<<B),B+1);
	//for(auto &i:dp)for(auto &j:i)j = B+1;
	for(int i = 0;i<N;i++){
		ans[i] = pull(mask[i]);
		push(arr[i]);
	}
	fill(dp,dp+(1<<B),B+1);
	done.reset();
	//for(auto &i:dp)for(auto &j:i)j = B+1;
	for(int i = N-1;i>=0;i--){
		ans[i] = min(ans[i],pull(mask[i]));
		push(arr[i]);
	}
	for(int i = 0;i<N;i++){
		cout<<sh[i]-ans[i]<<'\n';
	}
	return 0;
}

Compilation message

council.cpp: In function 'void push(int)':
council.cpp:43:56: error: no matching function for call to 'min(short int&, int&)'
   43 |   dp[((now>>tr)<<tr)|i] = min(dp[((now>>tr)<<tr)|i],tmp);
      |                                                        ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from council.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
council.cpp:43:56: note:   deduced conflicting types for parameter 'const _Tp' ('short int' and 'int')
   43 |   dp[((now>>tr)<<tr)|i] = min(dp[((now>>tr)<<tr)|i],tmp);
      |                                                        ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from council.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
council.cpp:43:56: note:   deduced conflicting types for parameter 'const _Tp' ('short int' and 'int')
   43 |   dp[((now>>tr)<<tr)|i] = min(dp[((now>>tr)<<tr)|i],tmp);
      |                                                        ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from council.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
council.cpp:43:56: note:   mismatched types 'std::initializer_list<_Tp>' and 'short int'
   43 |   dp[((now>>tr)<<tr)|i] = min(dp[((now>>tr)<<tr)|i],tmp);
      |                                                        ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from council.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
council.cpp:43:56: note:   mismatched types 'std::initializer_list<_Tp>' and 'short int'
   43 |   dp[((now>>tr)<<tr)|i] = min(dp[((now>>tr)<<tr)|i],tmp);
      |                                                        ^
council.cpp: In function 'int main()':
council.cpp:81:36: error: no matching function for call to 'min(short int&, int)'
   81 |   ans[i] = min(ans[i],pull(mask[i]));
      |                                    ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from council.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
council.cpp:81:36: note:   deduced conflicting types for parameter 'const _Tp' ('short int' and 'int')
   81 |   ans[i] = min(ans[i],pull(mask[i]));
      |                                    ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from council.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
council.cpp:81:36: note:   deduced conflicting types for parameter 'const _Tp' ('short int' and 'int')
   81 |   ans[i] = min(ans[i],pull(mask[i]));
      |                                    ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from council.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
council.cpp:81:36: note:   mismatched types 'std::initializer_list<_Tp>' and 'short int'
   81 |   ans[i] = min(ans[i],pull(mask[i]));
      |                                    ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from council.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
council.cpp:81:36: note:   mismatched types 'std::initializer_list<_Tp>' and 'short int'
   81 |   ans[i] = min(ans[i],pull(mask[i]));
      |                                    ^