Submission #68096

# Submission time Handle Problem Language Result Execution time Memory
68096 2018-08-15T22:19:06 Z MatheusLealV Chessboard (IZhO18_chessboard) C++17
0 / 100
33 ms 2336 KB
#include <bits/stdc++.h>
#define N 100050
#define f first
#define s second
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;

ll n, k, x[N], y[N], xf[N], yf[N];

long long ans = (2000000000000000000ll);

vector<ll> d;

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);

	cin>>n>>k;

	for(int i = 1; i <= k; i++) cin>>x[i]>>y[i]>>xf[i]>>yf[i];

	for(int i = 1; i <= k; i++) x[i] --, y[i] --, xf[i] --, yf[i] --;

	for(int i = 1; i <= sqrt(n); i++)
	{
		if((n % i) != 0) continue;

		d.push_back(i);

		if(i != n/i) d.push_back(n/i);
	}

	for(auto r: d)
	{	
		ll pretocerto = 0, pretoerrado = 0, tot;

		if(r == n) continue;

		tot = ( ((n/r) * (n/r)) + 1LL)/2LL;

		tot = (tot * r * r); 

		//if(r != 2) continue;

		for(int i = 1; i <= k; i++)
		{
			int linha = (x[i] % (2*r) < r ? 1 : 0), coluna = (y[i] % (2*r) < r ? 1 : 0);

			if(!linha) coluna = !coluna;

			if(!coluna) pretoerrado ++;

			else pretocerto ++;
		}

		//cout<<custo<<" "<<branco<<"\n";

		ans = min(ans, tot - pretocerto + pretoerrado);

		tot = ( ((n/r) * (n/r)) + 1LL)/2LL;

		tot = (tot * r * r); 

		ans = min(ans, tot + pretocerto - pretoerrado);

	}

	cout<<ans<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Incorrect 3 ms 588 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 2336 KB Output is correct
2 Incorrect 10 ms 2336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 2336 KB Output is correct
2 Incorrect 10 ms 2336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Incorrect 3 ms 588 KB Output isn't correct
3 Halted 0 ms 0 KB -