답안 #91701

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
91701 2018-12-29T10:32:23 Z emil_physmath Chessboard (IZhO18_chessboard) C++14
0 / 100
31 ms 2936 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';
	*/
	cout<<FindAns(n, k, 1)<<'\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);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 31 ms 2936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 31 ms 2936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -