Submission #378541

#TimeUsernameProblemLanguageResultExecution timeMemory
378541ElaineHuangChessboard (IZhO18_chessboard)C++14
47 / 100
85 ms748 KiB
#include<bits/stdc++.h>
#define debug 0
#define int long long
#define min trash
using namespace std;
int b[10005][2];//black squares
vector<int> factor;
int N;
int Min(int a,int b)
{
	return a<b?a:b;
}
int p(int f)
{
	int o=((N/f)*(N/f)/2)*f*f;//o->odd blocks
	int e=N*N-o;//e->even blocks
	if(debug) printf("f%d o%d e%d\n",f,o,e);//
	return Min(b[f][1]+e-b[f][0],b[f][0]+o-b[f][1]);//e黑//o黑 
}
signed main()
{
	int K,x1,x2,y1,y2;
	scanf("%lld %lld",&N,&K);
	int g=(int)sqrt(N);
	factor.clear();
	memset(b,0,sizeof(b));
	for(int i=1;i<=g;i++)
	{
		if(!(N%i))
		{
			factor.push_back(i);
		}
		if(debug) printf("i=%d\n",i);//
	}
	if(debug) printf("%d, g%d\n",factor.size(),g);//
	while(K--)
	{
		scanf("%lld %lld %lld %lld",&x1,&y1,&x2,&y2);
		x1--,y1--,x2--,y2--;
		for(int i=0;i<factor.size();i++)
		{
			int a;//determine 0 or 1
			int f;//factor
			f=factor[i];
			a=x1/f+y1/f;
			a%=2;
			b[f][a]++;
			
			if(f==N/f) break;
			if(f==1) continue;
			
			f=N/factor[i];
			a=x1/f+y1/f;
			a%=2;
			b[f][a]++;
		}
	}
	int ans=N*N;
	for(int i=0;i<factor.size();i++)
	{
		int f;
		f=factor[i];//p->paint幾格 
		ans=Min(p(f),ans);
		if(f==N/f) break;
		if(f==1) continue;
		f=N/f;
		ans=Min(p(f),ans);
	}
	printf("%lld\n",ans);
	return 0;
}

Compilation message (stderr)

chessboard.cpp: In function 'long long int p(long long int)':
chessboard.cpp:17:22: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
   17 |  if(debug) printf("f%d o%d e%d\n",f,o,e);//
      |                     ~^            ~
      |                      |            |
      |                      int          long long int
      |                     %lld
chessboard.cpp:17:26: warning: format '%d' expects argument of type 'int', but argument 3 has type 'long long int' [-Wformat=]
   17 |  if(debug) printf("f%d o%d e%d\n",f,o,e);//
      |                         ~^          ~
      |                          |          |
      |                          int        long long int
      |                         %lld
chessboard.cpp:17:30: warning: format '%d' expects argument of type 'int', but argument 4 has type 'long long int' [-Wformat=]
   17 |  if(debug) printf("f%d o%d e%d\n",f,o,e);//
      |                             ~^        ~
      |                              |        |
      |                              int      long long int
      |                             %lld
chessboard.cpp: In function 'int main()':
chessboard.cpp:33:24: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
   33 |   if(debug) printf("i=%d\n",i);//
      |                       ~^    ~
      |                        |    |
      |                        int  long long int
      |                       %lld
chessboard.cpp:35:21: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wformat=]
   35 |  if(debug) printf("%d, g%d\n",factor.size(),g);//
      |                    ~^         ~~~~~~~~~~~~~
      |                     |                    |
      |                     int                  std::vector<long long int>::size_type {aka long unsigned int}
      |                    %ld
chessboard.cpp:35:26: warning: format '%d' expects argument of type 'int', but argument 3 has type 'long long int' [-Wformat=]
   35 |  if(debug) printf("%d, g%d\n",factor.size(),g);//
      |                         ~^                  ~
      |                          |                  |
      |                          int                long long int
      |                         %lld
chessboard.cpp:40:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |   for(int i=0;i<factor.size();i++)
      |               ~^~~~~~~~~~~~~~
chessboard.cpp:59:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |  for(int i=0;i<factor.size();i++)
      |              ~^~~~~~~~~~~~~~
chessboard.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |  scanf("%lld %lld",&N,&K);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~
chessboard.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   38 |   scanf("%lld %lld %lld %lld",&x1,&y1,&x2,&y2);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...