Submission #47897

# Submission time Handle Problem Language Result Execution time Memory
47897 2018-05-08T13:07:11 Z dqhungdl Chessboard (IZhO18_chessboard) C++17
100 / 100
1161 ms 49840 KB
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int,int> ii;
int n,k,odd,even;
int64_t res=1e12;
vector<ii> g1[100005],g2[100005];
 
int Cal(int u,int v,int block)
{
	return ((u-1)/block+1+(v-1)/block+1)%2;
}

void Update(int i,int l,int r,int block,int val)
{
	int ll=(l-1)/block+2;
	int 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,(ll-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(int block)
{
	int64_t sodd=0,seven=0,tmp=n/block,codd,ceven;
	if(tmp%2==0)
		codd=ceven=int64_t(n)*int64_t(n)/int64_t(2);
	else
	{
		ceven=(int64_t(n)*int64_t(n)+int64_t(block)*int64_t(block))/int64_t(2);
		codd=int64_t(n)*int64_t(n)-ceven;
	}
	odd=even=0;
	for(int i=1;i<=n;i++)
	{
		if(i>1&&(i-1)/block+1!=(i-2)/block+1)
			swap(odd,even);
		for(int j=0;j<g1[i].size();j++)
			Update(i,g1[i][j].first,g1[i][j].second,block,1);
		sodd+=odd;
		seven+=even;
		for(int 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;
	int 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(int i=1;i<n;i++)
		if(n%i==0)
			Check(i);
	cout<<res;
}

Compilation message

chessboard.cpp: In function 'void Check(int)':
chessboard.cpp:60:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<g1[i].size();j++)
               ~^~~~~~~~~~~~~
chessboard.cpp:64:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int 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 5096 KB Output is correct
3 Correct 5 ms 5164 KB Output is correct
4 Correct 5 ms 5340 KB Output is correct
5 Correct 5 ms 5340 KB Output is correct
6 Correct 5 ms 5340 KB Output is correct
7 Correct 5 ms 5340 KB Output is correct
8 Correct 5 ms 5340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 7808 KB Output is correct
2 Correct 16 ms 7808 KB Output is correct
3 Correct 39 ms 7808 KB Output is correct
4 Correct 31 ms 7808 KB Output is correct
5 Correct 50 ms 7808 KB Output is correct
6 Correct 33 ms 7808 KB Output is correct
7 Correct 12 ms 7808 KB Output is correct
8 Correct 34 ms 7808 KB Output is correct
9 Correct 73 ms 8212 KB Output is correct
10 Correct 44 ms 8212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8212 KB Output is correct
2 Correct 5 ms 8212 KB Output is correct
3 Correct 5 ms 8212 KB Output is correct
4 Correct 6 ms 8212 KB Output is correct
5 Correct 7 ms 8212 KB Output is correct
6 Correct 5 ms 8212 KB Output is correct
7 Correct 6 ms 8212 KB Output is correct
8 Correct 6 ms 8212 KB Output is correct
9 Correct 6 ms 8212 KB Output is correct
10 Correct 5 ms 8212 KB Output is correct
11 Correct 6 ms 8212 KB Output is correct
12 Correct 5 ms 8212 KB Output is correct
13 Correct 6 ms 8212 KB Output is correct
14 Correct 6 ms 8212 KB Output is correct
15 Correct 5 ms 8212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8212 KB Output is correct
2 Correct 5 ms 8212 KB Output is correct
3 Correct 5 ms 8212 KB Output is correct
4 Correct 6 ms 8212 KB Output is correct
5 Correct 7 ms 8212 KB Output is correct
6 Correct 5 ms 8212 KB Output is correct
7 Correct 6 ms 8212 KB Output is correct
8 Correct 6 ms 8212 KB Output is correct
9 Correct 6 ms 8212 KB Output is correct
10 Correct 5 ms 8212 KB Output is correct
11 Correct 6 ms 8212 KB Output is correct
12 Correct 5 ms 8212 KB Output is correct
13 Correct 6 ms 8212 KB Output is correct
14 Correct 6 ms 8212 KB Output is correct
15 Correct 5 ms 8212 KB Output is correct
16 Correct 22 ms 8212 KB Output is correct
17 Correct 48 ms 8212 KB Output is correct
18 Correct 76 ms 8212 KB Output is correct
19 Correct 170 ms 8212 KB Output is correct
20 Correct 189 ms 8212 KB Output is correct
21 Correct 48 ms 8212 KB Output is correct
22 Correct 6 ms 8212 KB Output is correct
23 Correct 42 ms 8212 KB Output is correct
24 Correct 70 ms 8212 KB Output is correct
25 Correct 13 ms 8212 KB Output is correct
26 Correct 39 ms 8212 KB Output is correct
27 Correct 54 ms 8212 KB Output is correct
28 Correct 63 ms 8212 KB Output is correct
29 Correct 24 ms 8212 KB Output is correct
30 Correct 8 ms 8212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 7808 KB Output is correct
2 Correct 16 ms 7808 KB Output is correct
3 Correct 39 ms 7808 KB Output is correct
4 Correct 31 ms 7808 KB Output is correct
5 Correct 50 ms 7808 KB Output is correct
6 Correct 33 ms 7808 KB Output is correct
7 Correct 12 ms 7808 KB Output is correct
8 Correct 34 ms 7808 KB Output is correct
9 Correct 73 ms 8212 KB Output is correct
10 Correct 44 ms 8212 KB Output is correct
11 Correct 5 ms 8212 KB Output is correct
12 Correct 5 ms 8212 KB Output is correct
13 Correct 5 ms 8212 KB Output is correct
14 Correct 6 ms 8212 KB Output is correct
15 Correct 7 ms 8212 KB Output is correct
16 Correct 5 ms 8212 KB Output is correct
17 Correct 6 ms 8212 KB Output is correct
18 Correct 6 ms 8212 KB Output is correct
19 Correct 6 ms 8212 KB Output is correct
20 Correct 5 ms 8212 KB Output is correct
21 Correct 6 ms 8212 KB Output is correct
22 Correct 5 ms 8212 KB Output is correct
23 Correct 6 ms 8212 KB Output is correct
24 Correct 6 ms 8212 KB Output is correct
25 Correct 5 ms 8212 KB Output is correct
26 Correct 22 ms 8212 KB Output is correct
27 Correct 48 ms 8212 KB Output is correct
28 Correct 76 ms 8212 KB Output is correct
29 Correct 170 ms 8212 KB Output is correct
30 Correct 189 ms 8212 KB Output is correct
31 Correct 48 ms 8212 KB Output is correct
32 Correct 6 ms 8212 KB Output is correct
33 Correct 42 ms 8212 KB Output is correct
34 Correct 70 ms 8212 KB Output is correct
35 Correct 13 ms 8212 KB Output is correct
36 Correct 39 ms 8212 KB Output is correct
37 Correct 54 ms 8212 KB Output is correct
38 Correct 63 ms 8212 KB Output is correct
39 Correct 24 ms 8212 KB Output is correct
40 Correct 8 ms 8212 KB Output is correct
41 Correct 231 ms 9084 KB Output is correct
42 Correct 116 ms 9256 KB Output is correct
43 Correct 150 ms 9256 KB Output is correct
44 Correct 122 ms 9256 KB Output is correct
45 Correct 94 ms 9468 KB Output is correct
46 Correct 299 ms 9468 KB Output is correct
47 Correct 84 ms 9468 KB Output is correct
48 Correct 161 ms 9468 KB Output is correct
49 Correct 97 ms 9468 KB Output is correct
50 Correct 1083 ms 9468 KB Output is correct
51 Correct 1002 ms 9468 KB Output is correct
52 Correct 1161 ms 9468 KB Output is correct
53 Correct 1143 ms 9468 KB Output is correct
54 Correct 1024 ms 9468 KB Output is correct
55 Correct 1043 ms 9468 KB Output is correct
56 Correct 936 ms 9468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4984 KB Output is correct
2 Correct 5 ms 5096 KB Output is correct
3 Correct 5 ms 5164 KB Output is correct
4 Correct 5 ms 5340 KB Output is correct
5 Correct 5 ms 5340 KB Output is correct
6 Correct 5 ms 5340 KB Output is correct
7 Correct 5 ms 5340 KB Output is correct
8 Correct 5 ms 5340 KB Output is correct
9 Correct 58 ms 7808 KB Output is correct
10 Correct 16 ms 7808 KB Output is correct
11 Correct 39 ms 7808 KB Output is correct
12 Correct 31 ms 7808 KB Output is correct
13 Correct 50 ms 7808 KB Output is correct
14 Correct 33 ms 7808 KB Output is correct
15 Correct 12 ms 7808 KB Output is correct
16 Correct 34 ms 7808 KB Output is correct
17 Correct 73 ms 8212 KB Output is correct
18 Correct 44 ms 8212 KB Output is correct
19 Correct 5 ms 8212 KB Output is correct
20 Correct 5 ms 8212 KB Output is correct
21 Correct 5 ms 8212 KB Output is correct
22 Correct 6 ms 8212 KB Output is correct
23 Correct 7 ms 8212 KB Output is correct
24 Correct 5 ms 8212 KB Output is correct
25 Correct 6 ms 8212 KB Output is correct
26 Correct 6 ms 8212 KB Output is correct
27 Correct 6 ms 8212 KB Output is correct
28 Correct 5 ms 8212 KB Output is correct
29 Correct 6 ms 8212 KB Output is correct
30 Correct 5 ms 8212 KB Output is correct
31 Correct 6 ms 8212 KB Output is correct
32 Correct 6 ms 8212 KB Output is correct
33 Correct 5 ms 8212 KB Output is correct
34 Correct 22 ms 8212 KB Output is correct
35 Correct 48 ms 8212 KB Output is correct
36 Correct 76 ms 8212 KB Output is correct
37 Correct 170 ms 8212 KB Output is correct
38 Correct 189 ms 8212 KB Output is correct
39 Correct 48 ms 8212 KB Output is correct
40 Correct 6 ms 8212 KB Output is correct
41 Correct 42 ms 8212 KB Output is correct
42 Correct 70 ms 8212 KB Output is correct
43 Correct 13 ms 8212 KB Output is correct
44 Correct 39 ms 8212 KB Output is correct
45 Correct 54 ms 8212 KB Output is correct
46 Correct 63 ms 8212 KB Output is correct
47 Correct 24 ms 8212 KB Output is correct
48 Correct 8 ms 8212 KB Output is correct
49 Correct 231 ms 9084 KB Output is correct
50 Correct 116 ms 9256 KB Output is correct
51 Correct 150 ms 9256 KB Output is correct
52 Correct 122 ms 9256 KB Output is correct
53 Correct 94 ms 9468 KB Output is correct
54 Correct 299 ms 9468 KB Output is correct
55 Correct 84 ms 9468 KB Output is correct
56 Correct 161 ms 9468 KB Output is correct
57 Correct 97 ms 9468 KB Output is correct
58 Correct 1083 ms 9468 KB Output is correct
59 Correct 1002 ms 9468 KB Output is correct
60 Correct 1161 ms 9468 KB Output is correct
61 Correct 1143 ms 9468 KB Output is correct
62 Correct 1024 ms 9468 KB Output is correct
63 Correct 1043 ms 9468 KB Output is correct
64 Correct 936 ms 9468 KB Output is correct
65 Correct 5 ms 9468 KB Output is correct
66 Correct 5 ms 9468 KB Output is correct
67 Correct 1076 ms 9468 KB Output is correct
68 Correct 1074 ms 10876 KB Output is correct
69 Correct 948 ms 12248 KB Output is correct
70 Correct 1000 ms 14512 KB Output is correct
71 Correct 923 ms 16688 KB Output is correct
72 Correct 925 ms 18964 KB Output is correct
73 Correct 966 ms 21096 KB Output is correct
74 Correct 1037 ms 23244 KB Output is correct
75 Correct 925 ms 25068 KB Output is correct
76 Correct 1059 ms 27960 KB Output is correct
77 Correct 202 ms 30364 KB Output is correct
78 Correct 96 ms 32352 KB Output is correct
79 Correct 154 ms 34164 KB Output is correct
80 Correct 152 ms 36356 KB Output is correct
81 Correct 164 ms 38380 KB Output is correct
82 Correct 133 ms 40600 KB Output is correct
83 Correct 114 ms 42560 KB Output is correct
84 Correct 687 ms 45112 KB Output is correct
85 Correct 1083 ms 47216 KB Output is correct
86 Correct 111 ms 47216 KB Output is correct
87 Correct 109 ms 47216 KB Output is correct
88 Correct 1125 ms 49840 KB Output is correct
89 Correct 304 ms 49840 KB Output is correct
90 Correct 108 ms 49840 KB Output is correct