답안 #47896

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
47896 2018-05-08T12:57:47 Z dqhungdl Chessboard (IZhO18_chessboard) C++17
70 / 100
1188 ms 9496 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++)
	{
		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++)
               ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4984 KB Output is correct
2 Correct 5 ms 5096 KB Output is correct
3 Correct 5 ms 5172 KB Output is correct
4 Correct 5 ms 5172 KB Output is correct
5 Correct 5 ms 5248 KB Output is correct
6 Correct 5 ms 5248 KB Output is correct
7 Correct 5 ms 5324 KB Output is correct
8 Correct 5 ms 5324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 7932 KB Output is correct
2 Correct 16 ms 7932 KB Output is correct
3 Correct 36 ms 7932 KB Output is correct
4 Correct 32 ms 7932 KB Output is correct
5 Correct 50 ms 7932 KB Output is correct
6 Correct 32 ms 7932 KB Output is correct
7 Correct 10 ms 7932 KB Output is correct
8 Correct 30 ms 7932 KB Output is correct
9 Correct 68 ms 8316 KB Output is correct
10 Correct 46 ms 8316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8316 KB Output is correct
2 Correct 5 ms 8316 KB Output is correct
3 Correct 5 ms 8316 KB Output is correct
4 Correct 6 ms 8316 KB Output is correct
5 Correct 6 ms 8316 KB Output is correct
6 Correct 5 ms 8316 KB Output is correct
7 Correct 6 ms 8316 KB Output is correct
8 Correct 6 ms 8316 KB Output is correct
9 Correct 6 ms 8316 KB Output is correct
10 Correct 5 ms 8316 KB Output is correct
11 Correct 5 ms 8316 KB Output is correct
12 Correct 5 ms 8316 KB Output is correct
13 Correct 6 ms 8316 KB Output is correct
14 Correct 6 ms 8316 KB Output is correct
15 Correct 6 ms 8316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8316 KB Output is correct
2 Correct 5 ms 8316 KB Output is correct
3 Correct 5 ms 8316 KB Output is correct
4 Correct 6 ms 8316 KB Output is correct
5 Correct 6 ms 8316 KB Output is correct
6 Correct 5 ms 8316 KB Output is correct
7 Correct 6 ms 8316 KB Output is correct
8 Correct 6 ms 8316 KB Output is correct
9 Correct 6 ms 8316 KB Output is correct
10 Correct 5 ms 8316 KB Output is correct
11 Correct 5 ms 8316 KB Output is correct
12 Correct 5 ms 8316 KB Output is correct
13 Correct 6 ms 8316 KB Output is correct
14 Correct 6 ms 8316 KB Output is correct
15 Correct 6 ms 8316 KB Output is correct
16 Correct 23 ms 8316 KB Output is correct
17 Correct 45 ms 8316 KB Output is correct
18 Correct 66 ms 8316 KB Output is correct
19 Correct 168 ms 8316 KB Output is correct
20 Correct 178 ms 8316 KB Output is correct
21 Correct 43 ms 8316 KB Output is correct
22 Correct 6 ms 8316 KB Output is correct
23 Correct 40 ms 8316 KB Output is correct
24 Correct 59 ms 8316 KB Output is correct
25 Correct 12 ms 8316 KB Output is correct
26 Correct 42 ms 8316 KB Output is correct
27 Correct 52 ms 8316 KB Output is correct
28 Correct 60 ms 8316 KB Output is correct
29 Correct 21 ms 8316 KB Output is correct
30 Correct 7 ms 8316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 7932 KB Output is correct
2 Correct 16 ms 7932 KB Output is correct
3 Correct 36 ms 7932 KB Output is correct
4 Correct 32 ms 7932 KB Output is correct
5 Correct 50 ms 7932 KB Output is correct
6 Correct 32 ms 7932 KB Output is correct
7 Correct 10 ms 7932 KB Output is correct
8 Correct 30 ms 7932 KB Output is correct
9 Correct 68 ms 8316 KB Output is correct
10 Correct 46 ms 8316 KB Output is correct
11 Correct 5 ms 8316 KB Output is correct
12 Correct 5 ms 8316 KB Output is correct
13 Correct 5 ms 8316 KB Output is correct
14 Correct 6 ms 8316 KB Output is correct
15 Correct 6 ms 8316 KB Output is correct
16 Correct 5 ms 8316 KB Output is correct
17 Correct 6 ms 8316 KB Output is correct
18 Correct 6 ms 8316 KB Output is correct
19 Correct 6 ms 8316 KB Output is correct
20 Correct 5 ms 8316 KB Output is correct
21 Correct 5 ms 8316 KB Output is correct
22 Correct 5 ms 8316 KB Output is correct
23 Correct 6 ms 8316 KB Output is correct
24 Correct 6 ms 8316 KB Output is correct
25 Correct 6 ms 8316 KB Output is correct
26 Correct 23 ms 8316 KB Output is correct
27 Correct 45 ms 8316 KB Output is correct
28 Correct 66 ms 8316 KB Output is correct
29 Correct 168 ms 8316 KB Output is correct
30 Correct 178 ms 8316 KB Output is correct
31 Correct 43 ms 8316 KB Output is correct
32 Correct 6 ms 8316 KB Output is correct
33 Correct 40 ms 8316 KB Output is correct
34 Correct 59 ms 8316 KB Output is correct
35 Correct 12 ms 8316 KB Output is correct
36 Correct 42 ms 8316 KB Output is correct
37 Correct 52 ms 8316 KB Output is correct
38 Correct 60 ms 8316 KB Output is correct
39 Correct 21 ms 8316 KB Output is correct
40 Correct 7 ms 8316 KB Output is correct
41 Correct 222 ms 9040 KB Output is correct
42 Correct 125 ms 9468 KB Output is correct
43 Correct 164 ms 9468 KB Output is correct
44 Correct 125 ms 9468 KB Output is correct
45 Correct 93 ms 9496 KB Output is correct
46 Correct 246 ms 9496 KB Output is correct
47 Correct 75 ms 9496 KB Output is correct
48 Correct 129 ms 9496 KB Output is correct
49 Correct 88 ms 9496 KB Output is correct
50 Correct 852 ms 9496 KB Output is correct
51 Correct 917 ms 9496 KB Output is correct
52 Correct 856 ms 9496 KB Output is correct
53 Correct 872 ms 9496 KB Output is correct
54 Correct 817 ms 9496 KB Output is correct
55 Correct 1188 ms 9496 KB Output is correct
56 Correct 981 ms 9496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4984 KB Output is correct
2 Correct 5 ms 5096 KB Output is correct
3 Correct 5 ms 5172 KB Output is correct
4 Correct 5 ms 5172 KB Output is correct
5 Correct 5 ms 5248 KB Output is correct
6 Correct 5 ms 5248 KB Output is correct
7 Correct 5 ms 5324 KB Output is correct
8 Correct 5 ms 5324 KB Output is correct
9 Correct 48 ms 7932 KB Output is correct
10 Correct 16 ms 7932 KB Output is correct
11 Correct 36 ms 7932 KB Output is correct
12 Correct 32 ms 7932 KB Output is correct
13 Correct 50 ms 7932 KB Output is correct
14 Correct 32 ms 7932 KB Output is correct
15 Correct 10 ms 7932 KB Output is correct
16 Correct 30 ms 7932 KB Output is correct
17 Correct 68 ms 8316 KB Output is correct
18 Correct 46 ms 8316 KB Output is correct
19 Correct 5 ms 8316 KB Output is correct
20 Correct 5 ms 8316 KB Output is correct
21 Correct 5 ms 8316 KB Output is correct
22 Correct 6 ms 8316 KB Output is correct
23 Correct 6 ms 8316 KB Output is correct
24 Correct 5 ms 8316 KB Output is correct
25 Correct 6 ms 8316 KB Output is correct
26 Correct 6 ms 8316 KB Output is correct
27 Correct 6 ms 8316 KB Output is correct
28 Correct 5 ms 8316 KB Output is correct
29 Correct 5 ms 8316 KB Output is correct
30 Correct 5 ms 8316 KB Output is correct
31 Correct 6 ms 8316 KB Output is correct
32 Correct 6 ms 8316 KB Output is correct
33 Correct 6 ms 8316 KB Output is correct
34 Correct 23 ms 8316 KB Output is correct
35 Correct 45 ms 8316 KB Output is correct
36 Correct 66 ms 8316 KB Output is correct
37 Correct 168 ms 8316 KB Output is correct
38 Correct 178 ms 8316 KB Output is correct
39 Correct 43 ms 8316 KB Output is correct
40 Correct 6 ms 8316 KB Output is correct
41 Correct 40 ms 8316 KB Output is correct
42 Correct 59 ms 8316 KB Output is correct
43 Correct 12 ms 8316 KB Output is correct
44 Correct 42 ms 8316 KB Output is correct
45 Correct 52 ms 8316 KB Output is correct
46 Correct 60 ms 8316 KB Output is correct
47 Correct 21 ms 8316 KB Output is correct
48 Correct 7 ms 8316 KB Output is correct
49 Correct 222 ms 9040 KB Output is correct
50 Correct 125 ms 9468 KB Output is correct
51 Correct 164 ms 9468 KB Output is correct
52 Correct 125 ms 9468 KB Output is correct
53 Correct 93 ms 9496 KB Output is correct
54 Correct 246 ms 9496 KB Output is correct
55 Correct 75 ms 9496 KB Output is correct
56 Correct 129 ms 9496 KB Output is correct
57 Correct 88 ms 9496 KB Output is correct
58 Correct 852 ms 9496 KB Output is correct
59 Correct 917 ms 9496 KB Output is correct
60 Correct 856 ms 9496 KB Output is correct
61 Correct 872 ms 9496 KB Output is correct
62 Correct 817 ms 9496 KB Output is correct
63 Correct 1188 ms 9496 KB Output is correct
64 Correct 981 ms 9496 KB Output is correct
65 Correct 6 ms 9496 KB Output is correct
66 Correct 5 ms 9496 KB Output is correct
67 Incorrect 1053 ms 9496 KB Output isn't correct
68 Halted 0 ms 0 KB -