Submission #378541

# Submission time Handle Problem Language Result Execution time Memory
378541 2021-03-17T01:38:14 Z ElaineHuang Chessboard (IZhO18_chessboard) C++14
47 / 100
85 ms 748 KB
#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

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 time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 492 KB Output is correct
2 Correct 7 ms 492 KB Output is correct
3 Correct 15 ms 492 KB Output is correct
4 Correct 19 ms 492 KB Output is correct
5 Correct 21 ms 492 KB Output is correct
6 Correct 14 ms 492 KB Output is correct
7 Correct 3 ms 492 KB Output is correct
8 Correct 15 ms 492 KB Output is correct
9 Correct 35 ms 492 KB Output is correct
10 Correct 20 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 11 ms 492 KB Output is correct
17 Correct 29 ms 492 KB Output is correct
18 Correct 39 ms 492 KB Output is correct
19 Correct 79 ms 492 KB Output is correct
20 Correct 85 ms 620 KB Output is correct
21 Correct 27 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 21 ms 492 KB Output is correct
24 Correct 36 ms 492 KB Output is correct
25 Correct 6 ms 492 KB Output is correct
26 Correct 22 ms 492 KB Output is correct
27 Correct 30 ms 528 KB Output is correct
28 Correct 40 ms 492 KB Output is correct
29 Correct 12 ms 492 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 492 KB Output is correct
2 Correct 7 ms 492 KB Output is correct
3 Correct 15 ms 492 KB Output is correct
4 Correct 19 ms 492 KB Output is correct
5 Correct 21 ms 492 KB Output is correct
6 Correct 14 ms 492 KB Output is correct
7 Correct 3 ms 492 KB Output is correct
8 Correct 15 ms 492 KB Output is correct
9 Correct 35 ms 492 KB Output is correct
10 Correct 20 ms 620 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 11 ms 492 KB Output is correct
27 Correct 29 ms 492 KB Output is correct
28 Correct 39 ms 492 KB Output is correct
29 Correct 79 ms 492 KB Output is correct
30 Correct 85 ms 620 KB Output is correct
31 Correct 27 ms 492 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 21 ms 492 KB Output is correct
34 Correct 36 ms 492 KB Output is correct
35 Correct 6 ms 492 KB Output is correct
36 Correct 22 ms 492 KB Output is correct
37 Correct 30 ms 528 KB Output is correct
38 Correct 40 ms 492 KB Output is correct
39 Correct 12 ms 492 KB Output is correct
40 Correct 2 ms 492 KB Output is correct
41 Runtime error 1 ms 748 KB Execution killed with signal 11
42 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 24 ms 492 KB Output is correct
10 Correct 7 ms 492 KB Output is correct
11 Correct 15 ms 492 KB Output is correct
12 Correct 19 ms 492 KB Output is correct
13 Correct 21 ms 492 KB Output is correct
14 Correct 14 ms 492 KB Output is correct
15 Correct 3 ms 492 KB Output is correct
16 Correct 15 ms 492 KB Output is correct
17 Correct 35 ms 492 KB Output is correct
18 Correct 20 ms 620 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 1 ms 492 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 1 ms 492 KB Output is correct
34 Correct 11 ms 492 KB Output is correct
35 Correct 29 ms 492 KB Output is correct
36 Correct 39 ms 492 KB Output is correct
37 Correct 79 ms 492 KB Output is correct
38 Correct 85 ms 620 KB Output is correct
39 Correct 27 ms 492 KB Output is correct
40 Correct 1 ms 492 KB Output is correct
41 Correct 21 ms 492 KB Output is correct
42 Correct 36 ms 492 KB Output is correct
43 Correct 6 ms 492 KB Output is correct
44 Correct 22 ms 492 KB Output is correct
45 Correct 30 ms 528 KB Output is correct
46 Correct 40 ms 492 KB Output is correct
47 Correct 12 ms 492 KB Output is correct
48 Correct 2 ms 492 KB Output is correct
49 Runtime error 1 ms 748 KB Execution killed with signal 11
50 Halted 0 ms 0 KB -