Submission #334453

#TimeUsernameProblemLanguageResultExecution timeMemory
334453amunduzbaevChessboard (IZhO18_chessboard)C++14
39 / 100
115 ms2816 KiB
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ll long long 
#define ld long double 
#define pii pair<int, int>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define prc(n) fixed << setprecision(n)
#define fastios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi acos(-1);
const int inf = 1e9+7;
const int N = 1e3+5;

int x[N][N], pref[N][N];
vector<pii>vv;
ll ans, n, k;

void check(ll size){
	ll rem1 = ((n/size) * (n/size) +1)/2 * size * size, er1 = 0;
	for(int i=0;i<sz(vv);i++){
		ll x = vv[i].ff / size, y = vv[i].ss / size;
		if((x + y) %2 == 0) rem1--;
		else er1++;
	}
	ans = min(ans, er1 + rem1);
	
	rem1 = ((n/size)* (n/size))/2 * size * size, er1 = 0;
	for(int i=0;i<sz(vv);i++){
		ll x = vv[i].ff / size, y = vv[i].ss / size;
		if((x + y) % 2) rem1--;
		else er1++;
	}
	ans = min(ans, er1 + rem1);
}

void solve(){
	fastios
	ans = inf;
	cin>>n>>k;
	if(k == 0){
		ans = n*n/2;
		for(int i=2;i*1ll*i<=n;i++){
			if(n % i == 0){
				ll num = n/i;
				ans = min(ans, num * num /2 * i * i);
				num = i;
				ans = min(ans, num * num /2 * (n/i) * (n/i));
			}
		}
		cout<<ans<<"\n";
		return;
	}
	for(int i=0;i<k;i++){
		int a, b, c, d;
		cin>>a>>b>>c>>d;
		vv.pb({--a, --b});
	}
	for(int i=1;i *1ll * i<=n;i++){
		if(n % i == 0){
			check(i);
			if(n/i!=i && i!=1) check(n/i);
		}
	}
	cout<<ans<<"\n";
	return;
}
/*

3 3
1 3 1 3
2 3 2 3
1 1 1 1

3 4
1 1 1 1
1 3 1 3
2 3 2 3
3 3 3 3

5 8
2 1 2 1
3 1 3 1
5 2 5 2
1 5 1 5
2 3 2 3
2 4 2 4
3 3 3 3
4 3 4 3

6 8
1 2 1 2
2 1 2 1
3 3 3 3
3 4 3 4
4 3 4 3
4 4 4 4
3 6 3 6
5 5 5 5

*/
int main(){
	fastios
	int t = 1;
	//cin>>t;
	while(t--) solve();
	return 0;
}

#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...