Submission #91561

# Submission time Handle Problem Language Result Execution time Memory
91561 2018-12-28T11:58:40 Z emil_physmath Chessboard (IZhO18_chessboard) C++17
39 / 100
231 ms 15772 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 callLen);
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\n";
	}
	*/
	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, isWhite=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);
	}
	isWhite=n*n-isBlack;
	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 FindAns(int, int, int)':
chessboard.cpp:44:47: warning: variable 'isWhite' set but not used [-Wunused-but-set-variable]
  int shouldWhite=0, shouldBlack=0, isBlack=0, isWhite=0;
                                               ^~~~~~~
chessboard.cpp: In function 'int main()':
chessboard.cpp:26: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 256 KB Output is correct
2 Correct 2 ms 372 KB Output is correct
3 Correct 1 ms 372 KB Output is correct
4 Correct 2 ms 412 KB Output is correct
5 Correct 2 ms 412 KB Output is correct
6 Correct 2 ms 412 KB Output is correct
7 Correct 2 ms 472 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 1460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1460 KB Output is correct
2 Correct 2 ms 1460 KB Output is correct
3 Correct 2 ms 1460 KB Output is correct
4 Correct 2 ms 1460 KB Output is correct
5 Correct 2 ms 1460 KB Output is correct
6 Correct 2 ms 1460 KB Output is correct
7 Correct 2 ms 1460 KB Output is correct
8 Correct 2 ms 1460 KB Output is correct
9 Correct 2 ms 1460 KB Output is correct
10 Correct 2 ms 1460 KB Output is correct
11 Correct 2 ms 1460 KB Output is correct
12 Correct 2 ms 1460 KB Output is correct
13 Correct 2 ms 1460 KB Output is correct
14 Correct 2 ms 1460 KB Output is correct
15 Correct 2 ms 1460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1460 KB Output is correct
2 Correct 2 ms 1460 KB Output is correct
3 Correct 2 ms 1460 KB Output is correct
4 Correct 2 ms 1460 KB Output is correct
5 Correct 2 ms 1460 KB Output is correct
6 Correct 2 ms 1460 KB Output is correct
7 Correct 2 ms 1460 KB Output is correct
8 Correct 2 ms 1460 KB Output is correct
9 Correct 2 ms 1460 KB Output is correct
10 Correct 2 ms 1460 KB Output is correct
11 Correct 2 ms 1460 KB Output is correct
12 Correct 2 ms 1460 KB Output is correct
13 Correct 2 ms 1460 KB Output is correct
14 Correct 2 ms 1460 KB Output is correct
15 Correct 2 ms 1460 KB Output is correct
16 Correct 17 ms 1540 KB Output is correct
17 Correct 36 ms 3904 KB Output is correct
18 Correct 57 ms 5620 KB Output is correct
19 Correct 203 ms 6988 KB Output is correct
20 Correct 231 ms 8708 KB Output is correct
21 Correct 35 ms 9712 KB Output is correct
22 Correct 2 ms 9712 KB Output is correct
23 Correct 38 ms 9784 KB Output is correct
24 Correct 50 ms 12056 KB Output is correct
25 Correct 9 ms 12056 KB Output is correct
26 Correct 33 ms 12608 KB Output is correct
27 Correct 49 ms 13904 KB Output is correct
28 Correct 55 ms 15772 KB Output is correct
29 Correct 15 ms 15772 KB Output is correct
30 Correct 3 ms 15772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 1460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 372 KB Output is correct
3 Correct 1 ms 372 KB Output is correct
4 Correct 2 ms 412 KB Output is correct
5 Correct 2 ms 412 KB Output is correct
6 Correct 2 ms 412 KB Output is correct
7 Correct 2 ms 472 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Incorrect 30 ms 1460 KB Output isn't correct
10 Halted 0 ms 0 KB -