Submission #168599

# Submission time Handle Problem Language Result Execution time Memory
168599 2019-12-14T06:29:38 Z MrPlany Chessboard (IZhO18_chessboard) C++17
Compilation error
0 ms 0 KB
// In the name of God

#include <bits/stdc++.h>


#define ff first
#define ss second
#define pb push_back
#define pp pop_back
#define mp make_pair
#define db double
#define INF 1000000009
#define ll long long
#define all(a) a.begin(), a.end()
#define iOS ios_base::sync_with_stdio(false)

using namespace std;

const int N = 2e5 + 9, mod = 1e9+7;
int n,k;
struct gr{
	int x1,y1,x2,y2;
};
gr d[N];
int f(int v, int p){
	if(v%p==0) return v;
	return (v/p+1)*p;
}
int ters(int col){
	return (col==1?0:1);
}


int solve(int p, int col){
	
	int as_ak = 0 , as_gara = 0;
	
	if( (n/p)%2 == 0 ){
		as_gara = (n*n)/2;
	}
	else{
		int k = n/p;
		k = k/p;
		as_gara = k*k*p*p + (k+1)*(k+1)*p*p; 
		
		if( col == 0 ) as_gara = abs( (n*n*1LL) - as_gara );
	}
	
	int gara = 0 , ak = 0 ;
	for(int i=1;i<=k;i++){
		
		gr a = d[i] , b;
		b = a;
		while(true){
			
			gr c;
			
			c.x2 = f(a.x1,p);
			c.x1 = c.x2 - p + 1;
			
			c.y2 = f(a.y1,p);
			c.y1 = c.y2 - p + 1;
				
			gr e = c;
			e.x1 = max( c.x1 , a.x1 );
			e.y1 = max( c.y1 , a.y1 );
			e.x2 = min( c.x2 , a.x2 );
			e.y2 = min( c.y2 , a.y2 );
			
			int S = 1LL*abs( e.x2 - e.x1 + 1 ) * abs(e.y2 - e.y1 + 1);
			
			int o1 = f(c.x1,p);
			int o2 = f(c.y1,p);
			
			if( (o1/p)%2 == (o2/p)%2 ){
				if(col == 1) gara+=S;
				else ak+=S;
			}
			else{
				if(ters(col) == 1) gara+=S;
				else ak+=S;
			}
			
			if( e.x2 == a.x2 && e.y2 == a.y2 ) break;
			
			a.y1 = f(a.y1,p) + 1;
			
			if(a.y1 > a.y2) a.x1 = f(a.x1,p) + 1 , a.y1 = b.y1;
			
		}
		
		/*
		int o1 = f(a[i].x1,p);
		int o2 = f(a[i].y1,p);
		if( (o1/p)%2 == (o2/p)%2 ){
			if(col == 1) gara++;
			else ak++;
		}
		else{
			if( ters(col) == 1 ) gara++;
			else ak++;
		}
		*/
	}
	
	//cout << as_gara << " " << " " << ((as_gara - gara) + ak) << " " << p << " " << col << endl;
		// as_garada problema bar.
	return ((as_gara - gara) + ak);
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>k;
	for(int i=1;i<=k;i++){
		cin>>d[i].x1>>d[i].y1>>d[i].x2>>d[i].y2;
	}
	ll mn = INF;
	for(int i=1;i<n;i++){
		if(n%i == 0){
			mn = min( mn, solve(i,0) );
			mn = min( mn, solve(i,1) );
		}
	}
	cout <<mn;
	return 0;
}

Compilation message

chessboard.cpp: In function 'int solve(int, int)':
chessboard.cpp:36:6: warning: unused variable 'as_ak' [-Wunused-variable]
  int as_ak = 0 , as_gara = 0;
      ^~~~~
chessboard.cpp: In function 'int main()':
chessboard.cpp:120:29: error: no matching function for call to 'min(long long int&, int)'
    mn = min( mn, solve(i,0) );
                             ^
In file included from /usr/include/c++/7/bits/specfun.h:45:0,
                 from /usr/include/c++/7/cmath:1914,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:41,
                 from chessboard.cpp:3:
/usr/include/c++/7/bits/stl_algobase.h:195:5: note: candidate: template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)
     min(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:195:5: note:   template argument deduction/substitution failed:
chessboard.cpp:120:29: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
    mn = min( mn, solve(i,0) );
                             ^
In file included from /usr/include/c++/7/bits/specfun.h:45:0,
                 from /usr/include/c++/7/cmath:1914,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:41,
                 from chessboard.cpp:3:
/usr/include/c++/7/bits/stl_algobase.h:243:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:243:5: note:   template argument deduction/substitution failed:
chessboard.cpp:120:29: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
    mn = min( mn, solve(i,0) );
                             ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from chessboard.cpp:3:
/usr/include/c++/7/bits/stl_algo.h:3450:5: note: candidate: template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)
     min(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3450:5: note:   template argument deduction/substitution failed:
chessboard.cpp:120:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
    mn = min( mn, solve(i,0) );
                             ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from chessboard.cpp:3:
/usr/include/c++/7/bits/stl_algo.h:3456:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)
     min(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
chessboard.cpp:120:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
    mn = min( mn, solve(i,0) );
                             ^
chessboard.cpp:121:29: error: no matching function for call to 'min(long long int&, int)'
    mn = min( mn, solve(i,1) );
                             ^
In file included from /usr/include/c++/7/bits/specfun.h:45:0,
                 from /usr/include/c++/7/cmath:1914,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:41,
                 from chessboard.cpp:3:
/usr/include/c++/7/bits/stl_algobase.h:195:5: note: candidate: template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)
     min(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:195:5: note:   template argument deduction/substitution failed:
chessboard.cpp:121:29: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
    mn = min( mn, solve(i,1) );
                             ^
In file included from /usr/include/c++/7/bits/specfun.h:45:0,
                 from /usr/include/c++/7/cmath:1914,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:41,
                 from chessboard.cpp:3:
/usr/include/c++/7/bits/stl_algobase.h:243:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:243:5: note:   template argument deduction/substitution failed:
chessboard.cpp:121:29: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
    mn = min( mn, solve(i,1) );
                             ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from chessboard.cpp:3:
/usr/include/c++/7/bits/stl_algo.h:3450:5: note: candidate: template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)
     min(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3450:5: note:   template argument deduction/substitution failed:
chessboard.cpp:121:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
    mn = min( mn, solve(i,1) );
                             ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from chessboard.cpp:3:
/usr/include/c++/7/bits/stl_algo.h:3456:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)
     min(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
chessboard.cpp:121:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
    mn = min( mn, solve(i,1) );
                             ^