Submission #925390

#TimeUsernameProblemLanguageResultExecution timeMemory
925390esomerGarden (JOI23_garden)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
 
using namespace std;
 
#define int long long
 
struct DSU{
	vector<int> v;
	vector<bool> zero;
	int mx;
	void init(int n){
		v.assign(n, -1); mx = 0;
		zero.assign(n, false);
	}
	int get(int x){return v[x] < 0 ? x : v[x] = get(v[x]);}
	void unite(int x, int y){
		x = get(x); y = get(y);
		if(x == y) return;
		if(v[x] > v[y]) swap(x, y);
		v[x] += v[y]; v[y] = x; mx = max(mx, -v[x]);
	}
	void setZero(int i){
		zero[i] = true;
		int n = (int)v.size();
      	mx = max(mx, 1);
		if(zero[(i+n-1)%n]) unite(i, (i+n-1)%n);
		if(zero[(i+1)%n]) unite(i, (i+1)%n);
	}
};
 
signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	int N, M, D; cin >> N >> M >> D;
	vector<pair<int, int>> A(N);
	for(int i = 0; i < N; i++) cin >> A[i].first >> A[i].second;
	vector<pair<int, int>> B(M);
	for(int i = 0; i < M; i++) cin >> B[i].first >> B[i].second;
	vector<int> cols(D, 0);
	vector<vector<int>> rows(2*D);
	for(int i = 0; i < N; i++){
		cols[A[i].first]++;
		rows[A[i].second].push_back(i);
	}
	for(int i = 0; i < M; i++){
		cols[B[i].first]++;
		rows[B[i].second].push_back(N+i);
	}
	int ans = D * D;
	for(int startRow = 0; startRow < D; startRow++){
		int lft = N;
		vector<int> col = cols;
		DSU UF; UF.init(D);
		for(int i = 0; i < D; i++){
			if(col[i] == 0) UF.setZero(i);
		}
		for(int r = startRow; r < startRow + D; r++){
			for(int i : rows[r]){
				if(i < N){
					lft--;
				}else{
					i -= N;
					col[B[i].first]--;
					if(col[B[i].first] == 0) UF.setZero(B[i].first);
				}
			}
			if(lft > 0) continue;
			ans = min(ans, (r - startRow + 1) * (D - UF.mx));
		}
		for(int i : rows[startRow]){
			rows[startRow + D].push_back(i);
		}
	}
	cout << ans << "\n";
}

Compilation message (stderr)

garden.cpp: In member function 'void DSU::setZero(long long int)':
garden.cpp:25:22: error: no matching function for call to 'max(long long int&, int)'
   25 |        mx = max(mx, 1);
      |                      ^
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 garden.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
garden.cpp:25:22: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   25 |        mx = max(mx, 1);
      |                      ^
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 garden.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
garden.cpp:25:22: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   25 |        mx = max(mx, 1);
      |                      ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from garden.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
garden.cpp:25:22: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   25 |        mx = max(mx, 1);
      |                      ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from garden.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
garden.cpp:25:22: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   25 |        mx = max(mx, 1);
      |                      ^