Submission #341293

#TimeUsernameProblemLanguageResultExecution timeMemory
341293_aniChessboard (IZhO18_chessboard)C++17
70 / 100
373 ms262148 KiB
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;
vector<ll> dv;
vector<pair<int, int>> points;
ll ans;
int main()
{
	ll n, k;
	cin >> n >> k;
	ans = n * n;
	for (int i = 1; i < n; i++)
		if (n % i == 0)dv.push_back(i);
	for (int i = 0; i < k; i++)
	{
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		for (int x = a; x <= c; x++)
			for (int y = b; y <= d; y++)
				points.push_back({ x,y });
	}/*
	for (auto p : points)
		cerr << p.first << ' ' << p.second << '\n';*/
	for (ll d : dv)
	{
		ll blackans;
		ll q = n / d;
		if (q % 2)
			blackans = (n * n - d * d) / 2 + d * d;
		else blackans = n * n / 2;
		ll whiteans = n * n - blackans;
		//cerr << blackans << ' ' << whiteans << '\n';
		for (auto p : points)
		{
			int x = p.first, y = p.second;
			if ((((x + d - 1) / d) % 2) == (((y + d - 1) / d) % 2))
			{
				//cout << "!!" << x << ' ' << y << '\n';
				blackans--;
				whiteans++;
			}
			else
			{
				blackans++;
				whiteans--;
			}
		}
		ans = min(ans, min(blackans, whiteans));
		//if (d == 2)
		//	cout << blackans << ' ' << whiteans << '\n';
	}
	cout << ans;
	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...