Submission #91572

# Submission time Handle Problem Language Result Execution time Memory
91572 2018-12-28T13:08:20 Z emil_physmath Chessboard (IZhO18_chessboard) C++14
39 / 100
230 ms 2300 KB
#include <iostream>
#include <stdio.h>
using namespace std;
const int MAXK=100005;

int mini[MAXK], maxi[MAXK], minj[MAXK], maxj[MAXK];

int NumWhite(int, int, int, int, int cellLen);
int FindAns(int n, int k, int cellLen);
int main()
{
	//int len;
	//cin>>len;
	//while (true)
	//{
	//	int mini, minj, maxi, maxj;
	//	cin>>mini>>minj>>maxi>>maxj;
	//	cout<<"There are "<<NumWhite(mini, minj, maxi, maxj, len)
	//		<<" white cells in that subrectangle.\n";
	//	int realAns=0;
	//	for (int i=mini; i<=maxi; i++)
	//		for (int j=minj; j<=maxj; j++)
	//			if (((i+len-1)/len+(j+len-1)/len)%2==0)
	//				realAns++;
	//	if (NumWhite(mini, minj, maxi, maxj, len)==realAns)
	//		cout<<"OK\n";
	//	else
	//		cout<<"\aWA\n Should be "<<realAns<<".\n";
	//	cout<<endl;
	//}
	int n, k;
	cin>>n>>k;
	for (int i=0; i<k; i++)
		scanf("%d%d%d%d", mini+i, minj+i, maxi+i, maxj+i);
	int ans=n*n;
	for (int cellLen=1; cellLen*cellLen<=n; cellLen++)
		if (n%cellLen==0)
		{
			ans=min(ans, FindAns(n, k, cellLen));
			ans=min(ans, FindAns(n, k, n/cellLen));
		}
	cout<<ans<<'\n';

	char I;
	cin >> I;
	return 0;
}

int FindAns(int n, int k, int cellLen)
{
	if (cellLen>=n) return n*n;
	int shouldWhite=0, shouldBlack=0, isBlack=0;
	for (int i=0; i<k; i++)
	{
		shouldWhite+=NumWhite(mini[i], minj[i], maxi[i], maxj[i], cellLen);
		isBlack+=(maxi[i]-mini[i]+1)*(maxj[i]-minj[i]+1);
	}
	shouldBlack=(n*n-NumWhite(1, 1, n, n, cellLen))-(isBlack-shouldWhite);
	return min(shouldWhite+shouldBlack, n*n-(shouldWhite+shouldBlack));
}
int NumWhite(int mini, int minj, int maxi, int maxj, int len)
{
	if (!mini) mini=1;
	if (!minj) minj=1;
	if (mini==1 && minj==1)
	{
		int ans=0, i=maxi, j=maxj;
		ans+=len*len*(((i/len)*(j/len)+1)/2);
		if ((i/len)%2)
			ans+=(i%len)*((j/len)/2)*len;
		else
			ans+=(i%len)*((j/len+1)/2)*len;
		if ((j/len)%2)
			ans+=(j%len)*((i/len)/2)*len;
		else
			ans+=(j%len)*((i/len+1)/2)*len;
		if ((i/len)%2==(j/len)%2)
			ans+=(i%len)*(j%len);
		return ans;
	}
	return NumWhite(1, 1, maxi, maxj, len)-
		NumWhite(1, 1, maxi, minj-1, len)-NumWhite(1, 1, mini-1, maxj, len)+
		NumWhite(1, 1, mini-1, minj-1, len);
}

Compilation message

chessboard.cpp: In function 'int main()':
chessboard.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d%d", mini+i, minj+i, maxi+i, maxj+i);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 584 KB Output is correct
4 Correct 2 ms 584 KB Output is correct
5 Correct 2 ms 584 KB Output is correct
6 Correct 2 ms 584 KB Output is correct
7 Correct 2 ms 584 KB Output is correct
8 Correct 2 ms 584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 1488 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1488 KB Output is correct
2 Correct 2 ms 1488 KB Output is correct
3 Correct 2 ms 1488 KB Output is correct
4 Correct 2 ms 1488 KB Output is correct
5 Correct 2 ms 1488 KB Output is correct
6 Correct 2 ms 1488 KB Output is correct
7 Correct 2 ms 1488 KB Output is correct
8 Correct 2 ms 1488 KB Output is correct
9 Correct 2 ms 1488 KB Output is correct
10 Correct 2 ms 1488 KB Output is correct
11 Correct 2 ms 1488 KB Output is correct
12 Correct 2 ms 1488 KB Output is correct
13 Correct 2 ms 1488 KB Output is correct
14 Correct 2 ms 1488 KB Output is correct
15 Correct 2 ms 1488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1488 KB Output is correct
2 Correct 2 ms 1488 KB Output is correct
3 Correct 2 ms 1488 KB Output is correct
4 Correct 2 ms 1488 KB Output is correct
5 Correct 2 ms 1488 KB Output is correct
6 Correct 2 ms 1488 KB Output is correct
7 Correct 2 ms 1488 KB Output is correct
8 Correct 2 ms 1488 KB Output is correct
9 Correct 2 ms 1488 KB Output is correct
10 Correct 2 ms 1488 KB Output is correct
11 Correct 2 ms 1488 KB Output is correct
12 Correct 2 ms 1488 KB Output is correct
13 Correct 2 ms 1488 KB Output is correct
14 Correct 2 ms 1488 KB Output is correct
15 Correct 2 ms 1488 KB Output is correct
16 Correct 16 ms 1488 KB Output is correct
17 Correct 35 ms 1916 KB Output is correct
18 Correct 56 ms 2124 KB Output is correct
19 Correct 205 ms 2124 KB Output is correct
20 Correct 230 ms 2300 KB Output is correct
21 Correct 34 ms 2300 KB Output is correct
22 Correct 2 ms 2300 KB Output is correct
23 Correct 37 ms 2300 KB Output is correct
24 Correct 52 ms 2300 KB Output is correct
25 Correct 9 ms 2300 KB Output is correct
26 Correct 34 ms 2300 KB Output is correct
27 Correct 49 ms 2300 KB Output is correct
28 Correct 54 ms 2300 KB Output is correct
29 Correct 15 ms 2300 KB Output is correct
30 Correct 3 ms 2300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 1488 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 584 KB Output is correct
4 Correct 2 ms 584 KB Output is correct
5 Correct 2 ms 584 KB Output is correct
6 Correct 2 ms 584 KB Output is correct
7 Correct 2 ms 584 KB Output is correct
8 Correct 2 ms 584 KB Output is correct
9 Incorrect 31 ms 1488 KB Output isn't correct
10 Halted 0 ms 0 KB -