Submission #47890

# Submission time Handle Problem Language Result Execution time Memory
47890 2018-05-08T11:59:18 Z dqhungdl Chessboard (IZhO18_chessboard) C++17
47 / 100
2000 ms 38804 KB
#include <bits/stdc++.h>
using namespace std;

typedef pair<int64_t,int64_t> ii;
int64_t n,k,odd,even,res=1e12;
vector<ii> g1[100005],g2[100005];

int64_t Cal(int64_t u,int64_t v,int64_t block)
{
	return ((u-1)/block+1+(v-1)/block+1)%2;
}

void Update(int64_t i,int64_t l,int64_t r,int64_t block,int64_t val)
{
	int64_t ll=(l-1)/block+2;
	int64_t rr=(r-1)/block;
	if(ll==rr+2)
	{
		if(Cal(i,l,block)==1)
			odd+=(r-l+1)*val;
		else
			even+=(r-l+1)*val;
		return;
	}
	odd+=(rr-ll+1)/2*block*val;
	even+=(rr-ll+1)/2*block*val;
	if((rr-ll+1)%2==1)
	{
		if(Cal(i,(l-1)*block+1,block)==1)
			odd+=block*val;
		else
			even+=block*val;
	}
	if(Cal(i,l,block)==1)
		odd+=((ll-1)*block-l+1)*val;
	else
		even+=((ll-1)*block-l+1)*val;
	if(Cal(i,r,block)==1)
		odd+=(r-(rr*block))*val;
	else
		even+=(r-(rr*block))*val;
}

void Check(int64_t block)
{
	int64_t tmp=n/block;
	int64_t sodd=0,seven=0,codd,ceven;
	if(tmp%2==0)
		codd=ceven=n*n/2;
	else
	{
		ceven=(n*n+block*block)/2;
		codd=n*n-ceven;
	}
	odd=even=0;
	for(int64_t i=1;i<=n;i++)
	{
		for(int64_t j=0;j<g1[i].size();j++)
			Update(i,g1[i][j].first,g1[i][j].second,block,1);
		sodd+=odd;
		seven+=even;
		for(int64_t j=0;j<g2[i].size();j++)
			Update(i,g2[i][j].first,g2[i][j].second,block,-1);
	}
	res=min(res,min(codd-sodd+seven,ceven-seven+sodd));
}

int main()
{
	ios_base::sync_with_stdio(false);
	//freopen("TEST.INP","r",stdin);
	//freopen("TEST.OUT","w",stdout);
	cin>>n>>k;
	int64_t u1,v1,u2,v2;
	while(k--)
	{
		cin>>u1>>v1>>u2>>v2;
		g1[u1].push_back(ii(v1,v2));
		g2[u2].push_back(ii(v1,v2));
	}
	for(int64_t i=1;i<n;i++)
		if(n%i==0)
			Check(i);
	cout<<res;
}

Compilation message

chessboard.cpp: In function 'void Check(int64_t)':
chessboard.cpp:58:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int64_t j=0;j<g1[i].size();j++)
                   ~^~~~~~~~~~~~~
chessboard.cpp:62:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int64_t j=0;j<g2[i].size();j++)
                   ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4984 KB Output is correct
2 Correct 5 ms 5104 KB Output is correct
3 Correct 5 ms 5104 KB Output is correct
4 Correct 5 ms 5104 KB Output is correct
5 Correct 5 ms 5180 KB Output is correct
6 Correct 5 ms 5200 KB Output is correct
7 Correct 5 ms 5260 KB Output is correct
8 Correct 5 ms 5312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 10064 KB Output is correct
2 Correct 18 ms 10064 KB Output is correct
3 Correct 43 ms 10320 KB Output is correct
4 Correct 36 ms 11312 KB Output is correct
5 Correct 49 ms 13068 KB Output is correct
6 Correct 35 ms 13068 KB Output is correct
7 Correct 11 ms 13068 KB Output is correct
8 Correct 33 ms 13944 KB Output is correct
9 Correct 80 ms 18736 KB Output is correct
10 Correct 47 ms 18736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 18736 KB Output is correct
2 Correct 5 ms 18736 KB Output is correct
3 Correct 5 ms 18736 KB Output is correct
4 Correct 8 ms 18736 KB Output is correct
5 Correct 6 ms 18736 KB Output is correct
6 Correct 5 ms 18736 KB Output is correct
7 Correct 6 ms 18736 KB Output is correct
8 Correct 6 ms 18736 KB Output is correct
9 Correct 6 ms 18736 KB Output is correct
10 Correct 5 ms 18736 KB Output is correct
11 Correct 6 ms 18736 KB Output is correct
12 Correct 6 ms 18736 KB Output is correct
13 Correct 6 ms 18736 KB Output is correct
14 Correct 6 ms 18736 KB Output is correct
15 Correct 6 ms 18736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 18736 KB Output is correct
2 Correct 5 ms 18736 KB Output is correct
3 Correct 5 ms 18736 KB Output is correct
4 Correct 8 ms 18736 KB Output is correct
5 Correct 6 ms 18736 KB Output is correct
6 Correct 5 ms 18736 KB Output is correct
7 Correct 6 ms 18736 KB Output is correct
8 Correct 6 ms 18736 KB Output is correct
9 Correct 6 ms 18736 KB Output is correct
10 Correct 5 ms 18736 KB Output is correct
11 Correct 6 ms 18736 KB Output is correct
12 Correct 6 ms 18736 KB Output is correct
13 Correct 6 ms 18736 KB Output is correct
14 Correct 6 ms 18736 KB Output is correct
15 Correct 6 ms 18736 KB Output is correct
16 Correct 28 ms 18736 KB Output is correct
17 Correct 53 ms 21652 KB Output is correct
18 Correct 79 ms 23368 KB Output is correct
19 Correct 294 ms 24420 KB Output is correct
20 Correct 346 ms 26132 KB Output is correct
21 Correct 52 ms 27600 KB Output is correct
22 Correct 6 ms 27600 KB Output is correct
23 Correct 56 ms 27600 KB Output is correct
24 Correct 74 ms 29736 KB Output is correct
25 Correct 16 ms 29736 KB Output is correct
26 Correct 49 ms 29736 KB Output is correct
27 Correct 72 ms 31356 KB Output is correct
28 Correct 78 ms 33200 KB Output is correct
29 Correct 25 ms 33200 KB Output is correct
30 Correct 8 ms 33200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 10064 KB Output is correct
2 Correct 18 ms 10064 KB Output is correct
3 Correct 43 ms 10320 KB Output is correct
4 Correct 36 ms 11312 KB Output is correct
5 Correct 49 ms 13068 KB Output is correct
6 Correct 35 ms 13068 KB Output is correct
7 Correct 11 ms 13068 KB Output is correct
8 Correct 33 ms 13944 KB Output is correct
9 Correct 80 ms 18736 KB Output is correct
10 Correct 47 ms 18736 KB Output is correct
11 Correct 6 ms 18736 KB Output is correct
12 Correct 5 ms 18736 KB Output is correct
13 Correct 5 ms 18736 KB Output is correct
14 Correct 8 ms 18736 KB Output is correct
15 Correct 6 ms 18736 KB Output is correct
16 Correct 5 ms 18736 KB Output is correct
17 Correct 6 ms 18736 KB Output is correct
18 Correct 6 ms 18736 KB Output is correct
19 Correct 6 ms 18736 KB Output is correct
20 Correct 5 ms 18736 KB Output is correct
21 Correct 6 ms 18736 KB Output is correct
22 Correct 6 ms 18736 KB Output is correct
23 Correct 6 ms 18736 KB Output is correct
24 Correct 6 ms 18736 KB Output is correct
25 Correct 6 ms 18736 KB Output is correct
26 Correct 28 ms 18736 KB Output is correct
27 Correct 53 ms 21652 KB Output is correct
28 Correct 79 ms 23368 KB Output is correct
29 Correct 294 ms 24420 KB Output is correct
30 Correct 346 ms 26132 KB Output is correct
31 Correct 52 ms 27600 KB Output is correct
32 Correct 6 ms 27600 KB Output is correct
33 Correct 56 ms 27600 KB Output is correct
34 Correct 74 ms 29736 KB Output is correct
35 Correct 16 ms 29736 KB Output is correct
36 Correct 49 ms 29736 KB Output is correct
37 Correct 72 ms 31356 KB Output is correct
38 Correct 78 ms 33200 KB Output is correct
39 Correct 25 ms 33200 KB Output is correct
40 Correct 8 ms 33200 KB Output is correct
41 Correct 505 ms 36176 KB Output is correct
42 Correct 149 ms 38616 KB Output is correct
43 Correct 211 ms 38616 KB Output is correct
44 Correct 111 ms 38616 KB Output is correct
45 Correct 94 ms 38804 KB Output is correct
46 Correct 487 ms 38804 KB Output is correct
47 Correct 87 ms 38804 KB Output is correct
48 Correct 177 ms 38804 KB Output is correct
49 Correct 151 ms 38804 KB Output is correct
50 Execution timed out 2051 ms 38804 KB Time limit exceeded
51 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4984 KB Output is correct
2 Correct 5 ms 5104 KB Output is correct
3 Correct 5 ms 5104 KB Output is correct
4 Correct 5 ms 5104 KB Output is correct
5 Correct 5 ms 5180 KB Output is correct
6 Correct 5 ms 5200 KB Output is correct
7 Correct 5 ms 5260 KB Output is correct
8 Correct 5 ms 5312 KB Output is correct
9 Correct 73 ms 10064 KB Output is correct
10 Correct 18 ms 10064 KB Output is correct
11 Correct 43 ms 10320 KB Output is correct
12 Correct 36 ms 11312 KB Output is correct
13 Correct 49 ms 13068 KB Output is correct
14 Correct 35 ms 13068 KB Output is correct
15 Correct 11 ms 13068 KB Output is correct
16 Correct 33 ms 13944 KB Output is correct
17 Correct 80 ms 18736 KB Output is correct
18 Correct 47 ms 18736 KB Output is correct
19 Correct 6 ms 18736 KB Output is correct
20 Correct 5 ms 18736 KB Output is correct
21 Correct 5 ms 18736 KB Output is correct
22 Correct 8 ms 18736 KB Output is correct
23 Correct 6 ms 18736 KB Output is correct
24 Correct 5 ms 18736 KB Output is correct
25 Correct 6 ms 18736 KB Output is correct
26 Correct 6 ms 18736 KB Output is correct
27 Correct 6 ms 18736 KB Output is correct
28 Correct 5 ms 18736 KB Output is correct
29 Correct 6 ms 18736 KB Output is correct
30 Correct 6 ms 18736 KB Output is correct
31 Correct 6 ms 18736 KB Output is correct
32 Correct 6 ms 18736 KB Output is correct
33 Correct 6 ms 18736 KB Output is correct
34 Correct 28 ms 18736 KB Output is correct
35 Correct 53 ms 21652 KB Output is correct
36 Correct 79 ms 23368 KB Output is correct
37 Correct 294 ms 24420 KB Output is correct
38 Correct 346 ms 26132 KB Output is correct
39 Correct 52 ms 27600 KB Output is correct
40 Correct 6 ms 27600 KB Output is correct
41 Correct 56 ms 27600 KB Output is correct
42 Correct 74 ms 29736 KB Output is correct
43 Correct 16 ms 29736 KB Output is correct
44 Correct 49 ms 29736 KB Output is correct
45 Correct 72 ms 31356 KB Output is correct
46 Correct 78 ms 33200 KB Output is correct
47 Correct 25 ms 33200 KB Output is correct
48 Correct 8 ms 33200 KB Output is correct
49 Correct 505 ms 36176 KB Output is correct
50 Correct 149 ms 38616 KB Output is correct
51 Correct 211 ms 38616 KB Output is correct
52 Correct 111 ms 38616 KB Output is correct
53 Correct 94 ms 38804 KB Output is correct
54 Correct 487 ms 38804 KB Output is correct
55 Correct 87 ms 38804 KB Output is correct
56 Correct 177 ms 38804 KB Output is correct
57 Correct 151 ms 38804 KB Output is correct
58 Execution timed out 2051 ms 38804 KB Time limit exceeded
59 Halted 0 ms 0 KB -