Submission #787416

# Submission time Handle Problem Language Result Execution time Memory
787416 2023-07-19T07:08:37 Z willychan Chessboard (IZhO18_chessboard) C++14
100 / 100
367 ms 6508 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds
#define int ll
struct square{
	int x;int y;
	int xp;int yp;
};


signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n,k;cin>>n>>k;
	vector<ll> blackunion(n+1,0);
	vector<square> s(k);
	ll blacksum = 0;
	for(int i=0;i<k;i++){
		cin>>s[i].x>>s[i].xp>>s[i].y>>s[i].yp;
		s[i].x--;
		s[i].y--;
		s[i].xp--;
		s[i].yp--;
		blacksum+=1LL*(s[i].y-s[i].x+1)*(s[i].yp-s[i].xp+1);
	}
	ll minn = LONG_LONG_MAX;
	for(int d=1;d<n;d++){
		if(n%d) continue;
		for(int i=0;i<k;i++){
			ll hoz = 0;
			ll ver = 0;
			int g = (s[i].y/d)-(s[i].x/d);
			if(g==0) hoz = s[i].y-s[i].x+1;
			else{
				if(g&1){
					hoz = (d*(g/2))+d-(s[i].x%d);
				}else{
					hoz = d-(s[i].x%d)+(s[i].y%d)+1+(d*((g-1)/2));
				}
			}
			int h = (s[i].yp/d)-(s[i].xp/d);
			if(h==0) ver = s[i].yp-s[i].xp+1;
			else{
				if(h&1){
					ver = (d*(h/2))+d-(s[i].xp%d);
				}else{
					ver = d-(s[i].xp%d)+(s[i].yp%d)+1+(d*((h-1)/2));
				}
			}
			//cout<<ver<<" "<<hoz<<"\n";
			ll block = (ver*hoz)+(s[i].y-s[i].x+1-hoz)*(s[i].yp-s[i].xp+1-ver);
			if((((s[i].x/d)&1)^((s[i].xp/d)&1))==0) blackunion[d]+=block;	
			else blackunion[d]+=1LL*(s[i].y-s[i].x+1)*(s[i].yp-s[i].xp+1)-block;
		}
		ll allblack = 0;
		if((n/d)&1) allblack= 1LL*d*d*(1LL*(n/d)*(((n/d)/2))+((n/d)/2+1));
		else allblack = 1LL*d*d*(1LL*(n/d)*(n/d)/2);
		//cout<<d<<" "<<blackunion[d]<<" "<<allblack<<" "<<blacksum<<"\n";
		minn = min(minn,blacksum+allblack-2*blackunion[d]);
		minn = min(minn,2*blackunion[d]+(1LL*n*n-allblack)-blacksum);
	}
	cout<<minn<<"\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 3532 KB Output is correct
2 Correct 5 ms 1236 KB Output is correct
3 Correct 13 ms 2972 KB Output is correct
4 Correct 12 ms 2544 KB Output is correct
5 Correct 16 ms 3252 KB Output is correct
6 Correct 10 ms 2572 KB Output is correct
7 Correct 4 ms 852 KB Output is correct
8 Correct 12 ms 2508 KB Output is correct
9 Correct 32 ms 4148 KB Output is correct
10 Correct 16 ms 2904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 9 ms 1620 KB Output is correct
17 Correct 20 ms 3736 KB Output is correct
18 Correct 29 ms 4176 KB Output is correct
19 Correct 78 ms 3796 KB Output is correct
20 Correct 83 ms 4176 KB Output is correct
21 Correct 19 ms 3632 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 16 ms 2248 KB Output is correct
24 Correct 25 ms 3796 KB Output is correct
25 Correct 4 ms 724 KB Output is correct
26 Correct 16 ms 2860 KB Output is correct
27 Correct 24 ms 3216 KB Output is correct
28 Correct 28 ms 4052 KB Output is correct
29 Correct 10 ms 1884 KB Output is correct
30 Correct 2 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 3532 KB Output is correct
2 Correct 5 ms 1236 KB Output is correct
3 Correct 13 ms 2972 KB Output is correct
4 Correct 12 ms 2544 KB Output is correct
5 Correct 16 ms 3252 KB Output is correct
6 Correct 10 ms 2572 KB Output is correct
7 Correct 4 ms 852 KB Output is correct
8 Correct 12 ms 2508 KB Output is correct
9 Correct 32 ms 4148 KB Output is correct
10 Correct 16 ms 2904 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 328 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 9 ms 1620 KB Output is correct
27 Correct 20 ms 3736 KB Output is correct
28 Correct 29 ms 4176 KB Output is correct
29 Correct 78 ms 3796 KB Output is correct
30 Correct 83 ms 4176 KB Output is correct
31 Correct 19 ms 3632 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 16 ms 2248 KB Output is correct
34 Correct 25 ms 3796 KB Output is correct
35 Correct 4 ms 724 KB Output is correct
36 Correct 16 ms 2860 KB Output is correct
37 Correct 24 ms 3216 KB Output is correct
38 Correct 28 ms 4052 KB Output is correct
39 Correct 10 ms 1884 KB Output is correct
40 Correct 2 ms 460 KB Output is correct
41 Correct 69 ms 4436 KB Output is correct
42 Correct 32 ms 4808 KB Output is correct
43 Correct 45 ms 4468 KB Output is correct
44 Correct 31 ms 4692 KB Output is correct
45 Correct 29 ms 4932 KB Output is correct
46 Correct 84 ms 4764 KB Output is correct
47 Correct 26 ms 4548 KB Output is correct
48 Correct 37 ms 4588 KB Output is correct
49 Correct 32 ms 4436 KB Output is correct
50 Correct 306 ms 4576 KB Output is correct
51 Correct 331 ms 4768 KB Output is correct
52 Correct 304 ms 4564 KB Output is correct
53 Correct 325 ms 4748 KB Output is correct
54 Correct 307 ms 4520 KB Output is correct
55 Correct 337 ms 4864 KB Output is correct
56 Correct 297 ms 4428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 18 ms 3532 KB Output is correct
10 Correct 5 ms 1236 KB Output is correct
11 Correct 13 ms 2972 KB Output is correct
12 Correct 12 ms 2544 KB Output is correct
13 Correct 16 ms 3252 KB Output is correct
14 Correct 10 ms 2572 KB Output is correct
15 Correct 4 ms 852 KB Output is correct
16 Correct 12 ms 2508 KB Output is correct
17 Correct 32 ms 4148 KB Output is correct
18 Correct 16 ms 2904 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 1 ms 328 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 328 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 328 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 9 ms 1620 KB Output is correct
35 Correct 20 ms 3736 KB Output is correct
36 Correct 29 ms 4176 KB Output is correct
37 Correct 78 ms 3796 KB Output is correct
38 Correct 83 ms 4176 KB Output is correct
39 Correct 19 ms 3632 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 16 ms 2248 KB Output is correct
42 Correct 25 ms 3796 KB Output is correct
43 Correct 4 ms 724 KB Output is correct
44 Correct 16 ms 2860 KB Output is correct
45 Correct 24 ms 3216 KB Output is correct
46 Correct 28 ms 4052 KB Output is correct
47 Correct 10 ms 1884 KB Output is correct
48 Correct 2 ms 460 KB Output is correct
49 Correct 69 ms 4436 KB Output is correct
50 Correct 32 ms 4808 KB Output is correct
51 Correct 45 ms 4468 KB Output is correct
52 Correct 31 ms 4692 KB Output is correct
53 Correct 29 ms 4932 KB Output is correct
54 Correct 84 ms 4764 KB Output is correct
55 Correct 26 ms 4548 KB Output is correct
56 Correct 37 ms 4588 KB Output is correct
57 Correct 32 ms 4436 KB Output is correct
58 Correct 306 ms 4576 KB Output is correct
59 Correct 331 ms 4768 KB Output is correct
60 Correct 304 ms 4564 KB Output is correct
61 Correct 325 ms 4748 KB Output is correct
62 Correct 307 ms 4520 KB Output is correct
63 Correct 337 ms 4864 KB Output is correct
64 Correct 297 ms 4428 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 338 ms 4660 KB Output is correct
68 Correct 347 ms 6120 KB Output is correct
69 Correct 298 ms 5472 KB Output is correct
70 Correct 330 ms 5948 KB Output is correct
71 Correct 329 ms 5784 KB Output is correct
72 Correct 318 ms 5716 KB Output is correct
73 Correct 319 ms 5656 KB Output is correct
74 Correct 340 ms 6052 KB Output is correct
75 Correct 333 ms 5836 KB Output is correct
76 Correct 342 ms 6172 KB Output is correct
77 Correct 67 ms 6460 KB Output is correct
78 Correct 33 ms 6004 KB Output is correct
79 Correct 51 ms 5768 KB Output is correct
80 Correct 50 ms 5924 KB Output is correct
81 Correct 46 ms 5584 KB Output is correct
82 Correct 42 ms 6272 KB Output is correct
83 Correct 35 ms 5816 KB Output is correct
84 Correct 210 ms 6428 KB Output is correct
85 Correct 357 ms 6508 KB Output is correct
86 Correct 1 ms 980 KB Output is correct
87 Correct 1 ms 852 KB Output is correct
88 Correct 367 ms 6384 KB Output is correct
89 Correct 71 ms 2004 KB Output is correct
90 Correct 1 ms 980 KB Output is correct