Submission #47893

# Submission time Handle Problem Language Result Execution time Memory
47893 2018-05-08T12:20:34 Z dqhungdl Chessboard (IZhO18_chessboard) C++17
70 / 100
989 ms 10620 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,(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(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++)
	{
		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:58:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<g1[i].size();j++)
               ~^~~~~~~~~~~~~
chessboard.cpp:62: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 5096 KB Output is correct
4 Correct 5 ms 5096 KB Output is correct
5 Correct 5 ms 5164 KB Output is correct
6 Correct 5 ms 5164 KB Output is correct
7 Correct 5 ms 5164 KB Output is correct
8 Correct 5 ms 5164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 7800 KB Output is correct
2 Correct 26 ms 7800 KB Output is correct
3 Correct 39 ms 7800 KB Output is correct
4 Correct 31 ms 7800 KB Output is correct
5 Correct 47 ms 7800 KB Output is correct
6 Correct 31 ms 7800 KB Output is correct
7 Correct 11 ms 7800 KB Output is correct
8 Correct 32 ms 7800 KB Output is correct
9 Correct 76 ms 8244 KB Output is correct
10 Correct 65 ms 8244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8244 KB Output is correct
2 Correct 5 ms 8244 KB Output is correct
3 Correct 6 ms 8244 KB Output is correct
4 Correct 6 ms 8244 KB Output is correct
5 Correct 6 ms 8244 KB Output is correct
6 Correct 5 ms 8244 KB Output is correct
7 Correct 6 ms 8244 KB Output is correct
8 Correct 6 ms 8244 KB Output is correct
9 Correct 5 ms 8244 KB Output is correct
10 Correct 5 ms 8244 KB Output is correct
11 Correct 5 ms 8244 KB Output is correct
12 Correct 5 ms 8244 KB Output is correct
13 Correct 6 ms 8244 KB Output is correct
14 Correct 6 ms 8244 KB Output is correct
15 Correct 5 ms 8244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8244 KB Output is correct
2 Correct 5 ms 8244 KB Output is correct
3 Correct 6 ms 8244 KB Output is correct
4 Correct 6 ms 8244 KB Output is correct
5 Correct 6 ms 8244 KB Output is correct
6 Correct 5 ms 8244 KB Output is correct
7 Correct 6 ms 8244 KB Output is correct
8 Correct 6 ms 8244 KB Output is correct
9 Correct 5 ms 8244 KB Output is correct
10 Correct 5 ms 8244 KB Output is correct
11 Correct 5 ms 8244 KB Output is correct
12 Correct 5 ms 8244 KB Output is correct
13 Correct 6 ms 8244 KB Output is correct
14 Correct 6 ms 8244 KB Output is correct
15 Correct 5 ms 8244 KB Output is correct
16 Correct 21 ms 8244 KB Output is correct
17 Correct 45 ms 8244 KB Output is correct
18 Correct 61 ms 8244 KB Output is correct
19 Correct 159 ms 8244 KB Output is correct
20 Correct 177 ms 8244 KB Output is correct
21 Correct 44 ms 8244 KB Output is correct
22 Correct 6 ms 8244 KB Output is correct
23 Correct 39 ms 8244 KB Output is correct
24 Correct 57 ms 8244 KB Output is correct
25 Correct 12 ms 8244 KB Output is correct
26 Correct 37 ms 8244 KB Output is correct
27 Correct 51 ms 8244 KB Output is correct
28 Correct 59 ms 8244 KB Output is correct
29 Correct 21 ms 8244 KB Output is correct
30 Correct 7 ms 8244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 7800 KB Output is correct
2 Correct 26 ms 7800 KB Output is correct
3 Correct 39 ms 7800 KB Output is correct
4 Correct 31 ms 7800 KB Output is correct
5 Correct 47 ms 7800 KB Output is correct
6 Correct 31 ms 7800 KB Output is correct
7 Correct 11 ms 7800 KB Output is correct
8 Correct 32 ms 7800 KB Output is correct
9 Correct 76 ms 8244 KB Output is correct
10 Correct 65 ms 8244 KB Output is correct
11 Correct 5 ms 8244 KB Output is correct
12 Correct 5 ms 8244 KB Output is correct
13 Correct 6 ms 8244 KB Output is correct
14 Correct 6 ms 8244 KB Output is correct
15 Correct 6 ms 8244 KB Output is correct
16 Correct 5 ms 8244 KB Output is correct
17 Correct 6 ms 8244 KB Output is correct
18 Correct 6 ms 8244 KB Output is correct
19 Correct 5 ms 8244 KB Output is correct
20 Correct 5 ms 8244 KB Output is correct
21 Correct 5 ms 8244 KB Output is correct
22 Correct 5 ms 8244 KB Output is correct
23 Correct 6 ms 8244 KB Output is correct
24 Correct 6 ms 8244 KB Output is correct
25 Correct 5 ms 8244 KB Output is correct
26 Correct 21 ms 8244 KB Output is correct
27 Correct 45 ms 8244 KB Output is correct
28 Correct 61 ms 8244 KB Output is correct
29 Correct 159 ms 8244 KB Output is correct
30 Correct 177 ms 8244 KB Output is correct
31 Correct 44 ms 8244 KB Output is correct
32 Correct 6 ms 8244 KB Output is correct
33 Correct 39 ms 8244 KB Output is correct
34 Correct 57 ms 8244 KB Output is correct
35 Correct 12 ms 8244 KB Output is correct
36 Correct 37 ms 8244 KB Output is correct
37 Correct 51 ms 8244 KB Output is correct
38 Correct 59 ms 8244 KB Output is correct
39 Correct 21 ms 8244 KB Output is correct
40 Correct 7 ms 8244 KB Output is correct
41 Correct 221 ms 9084 KB Output is correct
42 Correct 121 ms 9424 KB Output is correct
43 Correct 185 ms 9424 KB Output is correct
44 Correct 89 ms 9424 KB Output is correct
45 Correct 91 ms 9424 KB Output is correct
46 Correct 236 ms 9424 KB Output is correct
47 Correct 92 ms 9424 KB Output is correct
48 Correct 127 ms 9424 KB Output is correct
49 Correct 90 ms 9424 KB Output is correct
50 Correct 854 ms 9424 KB Output is correct
51 Correct 898 ms 9424 KB Output is correct
52 Correct 870 ms 9424 KB Output is correct
53 Correct 886 ms 9424 KB Output is correct
54 Correct 801 ms 9424 KB Output is correct
55 Correct 924 ms 9424 KB Output is correct
56 Correct 836 ms 9424 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 5096 KB Output is correct
4 Correct 5 ms 5096 KB Output is correct
5 Correct 5 ms 5164 KB Output is correct
6 Correct 5 ms 5164 KB Output is correct
7 Correct 5 ms 5164 KB Output is correct
8 Correct 5 ms 5164 KB Output is correct
9 Correct 52 ms 7800 KB Output is correct
10 Correct 26 ms 7800 KB Output is correct
11 Correct 39 ms 7800 KB Output is correct
12 Correct 31 ms 7800 KB Output is correct
13 Correct 47 ms 7800 KB Output is correct
14 Correct 31 ms 7800 KB Output is correct
15 Correct 11 ms 7800 KB Output is correct
16 Correct 32 ms 7800 KB Output is correct
17 Correct 76 ms 8244 KB Output is correct
18 Correct 65 ms 8244 KB Output is correct
19 Correct 5 ms 8244 KB Output is correct
20 Correct 5 ms 8244 KB Output is correct
21 Correct 6 ms 8244 KB Output is correct
22 Correct 6 ms 8244 KB Output is correct
23 Correct 6 ms 8244 KB Output is correct
24 Correct 5 ms 8244 KB Output is correct
25 Correct 6 ms 8244 KB Output is correct
26 Correct 6 ms 8244 KB Output is correct
27 Correct 5 ms 8244 KB Output is correct
28 Correct 5 ms 8244 KB Output is correct
29 Correct 5 ms 8244 KB Output is correct
30 Correct 5 ms 8244 KB Output is correct
31 Correct 6 ms 8244 KB Output is correct
32 Correct 6 ms 8244 KB Output is correct
33 Correct 5 ms 8244 KB Output is correct
34 Correct 21 ms 8244 KB Output is correct
35 Correct 45 ms 8244 KB Output is correct
36 Correct 61 ms 8244 KB Output is correct
37 Correct 159 ms 8244 KB Output is correct
38 Correct 177 ms 8244 KB Output is correct
39 Correct 44 ms 8244 KB Output is correct
40 Correct 6 ms 8244 KB Output is correct
41 Correct 39 ms 8244 KB Output is correct
42 Correct 57 ms 8244 KB Output is correct
43 Correct 12 ms 8244 KB Output is correct
44 Correct 37 ms 8244 KB Output is correct
45 Correct 51 ms 8244 KB Output is correct
46 Correct 59 ms 8244 KB Output is correct
47 Correct 21 ms 8244 KB Output is correct
48 Correct 7 ms 8244 KB Output is correct
49 Correct 221 ms 9084 KB Output is correct
50 Correct 121 ms 9424 KB Output is correct
51 Correct 185 ms 9424 KB Output is correct
52 Correct 89 ms 9424 KB Output is correct
53 Correct 91 ms 9424 KB Output is correct
54 Correct 236 ms 9424 KB Output is correct
55 Correct 92 ms 9424 KB Output is correct
56 Correct 127 ms 9424 KB Output is correct
57 Correct 90 ms 9424 KB Output is correct
58 Correct 854 ms 9424 KB Output is correct
59 Correct 898 ms 9424 KB Output is correct
60 Correct 870 ms 9424 KB Output is correct
61 Correct 886 ms 9424 KB Output is correct
62 Correct 801 ms 9424 KB Output is correct
63 Correct 924 ms 9424 KB Output is correct
64 Correct 836 ms 9424 KB Output is correct
65 Correct 5 ms 9424 KB Output is correct
66 Correct 5 ms 9424 KB Output is correct
67 Incorrect 989 ms 10620 KB Output isn't correct
68 Halted 0 ms 0 KB -