Submission #343799

# Submission time Handle Problem Language Result Execution time Memory
343799 2021-01-04T13:41:38 Z _ani Chessboard (IZhO18_chessboard) C++17
8 / 100
82 ms 2912 KB
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;
struct el {
	int a, b, c, d;
};
vector<ll> dv;
vector<el> points;
ll ans;
int prefans(int x, int y, int k, int f)
{
	int ans;
	int ab = y / k, a;
	a = (ab + 1) / 2 + 1;
	a *= k;
	if (ab % 2 == 0)a += y % k;
	if (x <= k)
		ans = x * a;
	else
	{
		int aa = y - a;
		int q = x / k;
		ans = aa * (q / 2) * k;
		ans += a * ((q + 1) / 2) * k;
		if (q % 2)
			ans += aa * (x % k);
		else ans += a * (x % k);
	}
	if (f == 1)
		return ans;
	else return x * y - 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;
		points.push_back({ a,b,c,d });
	}/*
	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;
		for (auto p : points)
		{
			blackans = blackans + 2 * prefans(p.a, p.b, d, 1) - p.a * p.b - 2 * prefans(p.c, p.d, d, 1) + p.c * p.d;
			whiteans = whiteans + 2 * prefans(p.a, p.b, d, 0) - p.a * p.b - 2 * prefans(p.c, p.d, d, 0) + p.c * p.d;
		}
		ans = min(ans, min(blackans, whiteans));
	}
	cout << ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 82 ms 2912 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 82 ms 2912 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Incorrect 82 ms 2912 KB Output isn't correct
10 Halted 0 ms 0 KB -