Submission #47892

# Submission time Handle Problem Language Result Execution time Memory
47892 2018-05-08T12:03:29 Z dqhungdl Chessboard (IZhO18_chessboard) C++17
47 / 100
2000 ms 10496 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];

void ReadInt(int64_t &number)
{
    number=0;
    int64_t c=getchar();
    while(c<'0'||c>'9')
    	c=getchar();
    for(;('0'<=c&&c<='9');c=getchar())
        number=number*10+c-48;  
}

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);
	ReadInt(n);
	ReadInt(k);
	int64_t u1,v1,u2,v2;
	while(k--)
	{
		ReadInt(u1);
		ReadInt(v1);
		ReadInt(u2);
		ReadInt(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:68:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int64_t j=0;j<g1[i].size();j++)
                   ~^~~~~~~~~~~~~
chessboard.cpp:72: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 5096 KB Output is correct
3 Correct 5 ms 5148 KB Output is correct
4 Correct 5 ms 5148 KB Output is correct
5 Correct 5 ms 5148 KB Output is correct
6 Correct 5 ms 5240 KB Output is correct
7 Correct 5 ms 5264 KB Output is correct
8 Correct 5 ms 5280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 8556 KB Output is correct
2 Correct 14 ms 8556 KB Output is correct
3 Correct 31 ms 8556 KB Output is correct
4 Correct 25 ms 8556 KB Output is correct
5 Correct 40 ms 8556 KB Output is correct
6 Correct 26 ms 8556 KB Output is correct
7 Correct 9 ms 8556 KB Output is correct
8 Correct 25 ms 8556 KB Output is correct
9 Correct 55 ms 9852 KB Output is correct
10 Correct 33 ms 9852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9852 KB Output is correct
2 Correct 5 ms 9852 KB Output is correct
3 Correct 5 ms 9852 KB Output is correct
4 Correct 6 ms 9852 KB Output is correct
5 Correct 5 ms 9852 KB Output is correct
6 Correct 5 ms 9852 KB Output is correct
7 Correct 6 ms 9852 KB Output is correct
8 Correct 6 ms 9852 KB Output is correct
9 Correct 5 ms 9852 KB Output is correct
10 Correct 5 ms 9852 KB Output is correct
11 Correct 5 ms 9852 KB Output is correct
12 Correct 5 ms 9852 KB Output is correct
13 Correct 6 ms 9852 KB Output is correct
14 Correct 6 ms 9852 KB Output is correct
15 Correct 5 ms 9852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9852 KB Output is correct
2 Correct 5 ms 9852 KB Output is correct
3 Correct 5 ms 9852 KB Output is correct
4 Correct 6 ms 9852 KB Output is correct
5 Correct 5 ms 9852 KB Output is correct
6 Correct 5 ms 9852 KB Output is correct
7 Correct 6 ms 9852 KB Output is correct
8 Correct 6 ms 9852 KB Output is correct
9 Correct 5 ms 9852 KB Output is correct
10 Correct 5 ms 9852 KB Output is correct
11 Correct 5 ms 9852 KB Output is correct
12 Correct 5 ms 9852 KB Output is correct
13 Correct 6 ms 9852 KB Output is correct
14 Correct 6 ms 9852 KB Output is correct
15 Correct 5 ms 9852 KB Output is correct
16 Correct 21 ms 9852 KB Output is correct
17 Correct 36 ms 9852 KB Output is correct
18 Correct 58 ms 9852 KB Output is correct
19 Correct 271 ms 9852 KB Output is correct
20 Correct 305 ms 9852 KB Output is correct
21 Correct 34 ms 9852 KB Output is correct
22 Correct 6 ms 9852 KB Output is correct
23 Correct 47 ms 9852 KB Output is correct
24 Correct 54 ms 9852 KB Output is correct
25 Correct 15 ms 9852 KB Output is correct
26 Correct 36 ms 9852 KB Output is correct
27 Correct 59 ms 9852 KB Output is correct
28 Correct 57 ms 9852 KB Output is correct
29 Correct 18 ms 9852 KB Output is correct
30 Correct 7 ms 9852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 8556 KB Output is correct
2 Correct 14 ms 8556 KB Output is correct
3 Correct 31 ms 8556 KB Output is correct
4 Correct 25 ms 8556 KB Output is correct
5 Correct 40 ms 8556 KB Output is correct
6 Correct 26 ms 8556 KB Output is correct
7 Correct 9 ms 8556 KB Output is correct
8 Correct 25 ms 8556 KB Output is correct
9 Correct 55 ms 9852 KB Output is correct
10 Correct 33 ms 9852 KB Output is correct
11 Correct 5 ms 9852 KB Output is correct
12 Correct 5 ms 9852 KB Output is correct
13 Correct 5 ms 9852 KB Output is correct
14 Correct 6 ms 9852 KB Output is correct
15 Correct 5 ms 9852 KB Output is correct
16 Correct 5 ms 9852 KB Output is correct
17 Correct 6 ms 9852 KB Output is correct
18 Correct 6 ms 9852 KB Output is correct
19 Correct 5 ms 9852 KB Output is correct
20 Correct 5 ms 9852 KB Output is correct
21 Correct 5 ms 9852 KB Output is correct
22 Correct 5 ms 9852 KB Output is correct
23 Correct 6 ms 9852 KB Output is correct
24 Correct 6 ms 9852 KB Output is correct
25 Correct 5 ms 9852 KB Output is correct
26 Correct 21 ms 9852 KB Output is correct
27 Correct 36 ms 9852 KB Output is correct
28 Correct 58 ms 9852 KB Output is correct
29 Correct 271 ms 9852 KB Output is correct
30 Correct 305 ms 9852 KB Output is correct
31 Correct 34 ms 9852 KB Output is correct
32 Correct 6 ms 9852 KB Output is correct
33 Correct 47 ms 9852 KB Output is correct
34 Correct 54 ms 9852 KB Output is correct
35 Correct 15 ms 9852 KB Output is correct
36 Correct 36 ms 9852 KB Output is correct
37 Correct 59 ms 9852 KB Output is correct
38 Correct 57 ms 9852 KB Output is correct
39 Correct 18 ms 9852 KB Output is correct
40 Correct 7 ms 9852 KB Output is correct
41 Correct 460 ms 9852 KB Output is correct
42 Correct 125 ms 10364 KB Output is correct
43 Correct 272 ms 10364 KB Output is correct
44 Correct 108 ms 10364 KB Output is correct
45 Correct 83 ms 10496 KB Output is correct
46 Correct 428 ms 10496 KB Output is correct
47 Correct 72 ms 10496 KB Output is correct
48 Correct 201 ms 10496 KB Output is correct
49 Correct 104 ms 10496 KB Output is correct
50 Execution timed out 2074 ms 10496 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 5096 KB Output is correct
3 Correct 5 ms 5148 KB Output is correct
4 Correct 5 ms 5148 KB Output is correct
5 Correct 5 ms 5148 KB Output is correct
6 Correct 5 ms 5240 KB Output is correct
7 Correct 5 ms 5264 KB Output is correct
8 Correct 5 ms 5280 KB Output is correct
9 Correct 49 ms 8556 KB Output is correct
10 Correct 14 ms 8556 KB Output is correct
11 Correct 31 ms 8556 KB Output is correct
12 Correct 25 ms 8556 KB Output is correct
13 Correct 40 ms 8556 KB Output is correct
14 Correct 26 ms 8556 KB Output is correct
15 Correct 9 ms 8556 KB Output is correct
16 Correct 25 ms 8556 KB Output is correct
17 Correct 55 ms 9852 KB Output is correct
18 Correct 33 ms 9852 KB Output is correct
19 Correct 5 ms 9852 KB Output is correct
20 Correct 5 ms 9852 KB Output is correct
21 Correct 5 ms 9852 KB Output is correct
22 Correct 6 ms 9852 KB Output is correct
23 Correct 5 ms 9852 KB Output is correct
24 Correct 5 ms 9852 KB Output is correct
25 Correct 6 ms 9852 KB Output is correct
26 Correct 6 ms 9852 KB Output is correct
27 Correct 5 ms 9852 KB Output is correct
28 Correct 5 ms 9852 KB Output is correct
29 Correct 5 ms 9852 KB Output is correct
30 Correct 5 ms 9852 KB Output is correct
31 Correct 6 ms 9852 KB Output is correct
32 Correct 6 ms 9852 KB Output is correct
33 Correct 5 ms 9852 KB Output is correct
34 Correct 21 ms 9852 KB Output is correct
35 Correct 36 ms 9852 KB Output is correct
36 Correct 58 ms 9852 KB Output is correct
37 Correct 271 ms 9852 KB Output is correct
38 Correct 305 ms 9852 KB Output is correct
39 Correct 34 ms 9852 KB Output is correct
40 Correct 6 ms 9852 KB Output is correct
41 Correct 47 ms 9852 KB Output is correct
42 Correct 54 ms 9852 KB Output is correct
43 Correct 15 ms 9852 KB Output is correct
44 Correct 36 ms 9852 KB Output is correct
45 Correct 59 ms 9852 KB Output is correct
46 Correct 57 ms 9852 KB Output is correct
47 Correct 18 ms 9852 KB Output is correct
48 Correct 7 ms 9852 KB Output is correct
49 Correct 460 ms 9852 KB Output is correct
50 Correct 125 ms 10364 KB Output is correct
51 Correct 272 ms 10364 KB Output is correct
52 Correct 108 ms 10364 KB Output is correct
53 Correct 83 ms 10496 KB Output is correct
54 Correct 428 ms 10496 KB Output is correct
55 Correct 72 ms 10496 KB Output is correct
56 Correct 201 ms 10496 KB Output is correct
57 Correct 104 ms 10496 KB Output is correct
58 Execution timed out 2074 ms 10496 KB Time limit exceeded
59 Halted 0 ms 0 KB -