Submission #68091

# Submission time Handle Problem Language Result Execution time Memory
68091 2018-08-15T21:58:50 Z MatheusLealV Chessboard (IZhO18_chessboard) C++17
0 / 100
57 ms 2940 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;

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

ll ans = N * N;

vector<int> 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;

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

		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;

			//cout<<x[i]<<" "<<y[i]<<" COR = "<<linha<<" "<<coluna<<"\n";

			if(!coluna) pretoerrado ++;

			else pretocerto ++;
		}

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

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

	cout<<ans<<"\n";
}

Compilation message

chessboard.cpp:11:12: warning: integer overflow in expression [-Woverflow]
 ll ans = N * N;
            ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Incorrect 3 ms 456 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 57 ms 2940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 57 ms 2940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Incorrect 3 ms 456 KB Output isn't correct
3 Halted 0 ms 0 KB -