Submission #342183

# Submission time Handle Problem Language Result Execution time Memory
342183 2021-01-01T14:41:52 Z David_M Chessboard (IZhO18_chessboard) C++14
100 / 100
839 ms 6808 KB
#include <bits/stdc++.h> 
#define ll long long
#define pb push_back
#define F first
#define S second
using namespace std;
const ll N=1000006, INF=1e18;
ll e, t, n, m, a[N], i, j, k, u, x1, x2, X1, X2, ans[N], xl[N], yl[N], xr[N], yr[N], Ans, sz, w, r, X, Y, xx, yy, xxx, yyy, A, B;
vector <int> v;

ll calc(ll x, ll y){
	if(!x||!y) return 0;
	t=0;
	X=x/e*e;
	Y=y/e*e;
	
	xx=X/e;
	yy=Y/e;
	
	t+=(((xx*yy+1)/2)*e*e);
	xxx=x-X;
	yyy=y-Y;
	
	if(xx&1) B=(yy>>1);
	else B=(yy+1>>1);
	
	if(yy&1) A=(xx>>1);
	else A=(xx+1>>1);
	
	t+=(B*xxx*e);
	t+=(A*yyy*e);
	
	if(!((X/e+Y/e)&1)) t+=(xxx*yyy);
//	cout<<x<<" "<<y<<" "<<t<<endl;
	return t;
}

int main(){ios_base::sync_with_stdio(false), cin.tie(0);
	long long ee;
	cin>>n>>m;
	Ans=INF;
		
	for (int i=1; i<=m; i++)
		cin>>xl[i]>>yl[i]>>xr[i]>>yr[i],
		a[i]=(xr[i]-xl[i]+1)*(yr[i]-yl[i]+1);
		
	
	for (int i=1; i<n; i++)
		if(n%i==0)
			v.pb(i);
	k=v.size();
	
	for(int i=0; i<k; i++){
		e=v[i];
		ans[i]=(n*n/e/e+1)/2*e*e;//cout<<ans[i]<<" ";
		for (int j=1; j<=m; j++)
			ans[i]+=a[j],
			ans[i]-=2*(calc(xr[j], yr[j])-(calc(xl[j]-1, yr[j])+calc(xr[j], yl[j]-1)-calc(xl[j]-1, yl[j]-1)));
		Ans=min(Ans, min(ans[i], n*n-ans[i]));//cout<<ans[i]<<endl;
	}
	cout<<Ans;
	
}
/*
6 8
3 3 3 3
1 2 1 2
3 4 3 4
5 5 5 5
4 3 4 3
4 4 4 4
2 1 2 1
3 6 3 6

4 1
4 1 4 4
*/

Compilation message

chessboard.cpp: In function 'long long int calc(long long int, long long int)':
chessboard.cpp:25:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   25 |  else B=(yy+1>>1);
      |          ~~^~
chessboard.cpp:28:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   28 |  else A=(xx+1>>1);
      |          ~~^~
chessboard.cpp: In function 'int main()':
chessboard.cpp:39:12: warning: unused variable 'ee' [-Wunused-variable]
   39 |  long long ee;
      |            ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 4332 KB Output is correct
2 Correct 8 ms 1388 KB Output is correct
3 Correct 18 ms 2924 KB Output is correct
4 Correct 20 ms 3052 KB Output is correct
5 Correct 26 ms 3820 KB Output is correct
6 Correct 17 ms 2540 KB Output is correct
7 Correct 4 ms 876 KB Output is correct
8 Correct 17 ms 2540 KB Output is correct
9 Correct 41 ms 5996 KB Output is correct
10 Correct 23 ms 3564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 14 ms 1900 KB Output is correct
17 Correct 32 ms 5100 KB Output is correct
18 Correct 49 ms 5868 KB Output is correct
19 Correct 165 ms 5228 KB Output is correct
20 Correct 185 ms 5888 KB Output is correct
21 Correct 31 ms 4844 KB Output is correct
22 Correct 2 ms 312 KB Output is correct
23 Correct 31 ms 2668 KB Output is correct
24 Correct 46 ms 5560 KB Output is correct
25 Correct 7 ms 876 KB Output is correct
26 Correct 28 ms 3564 KB Output is correct
27 Correct 42 ms 4204 KB Output is correct
28 Correct 48 ms 5612 KB Output is correct
29 Correct 13 ms 2284 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 4332 KB Output is correct
2 Correct 8 ms 1388 KB Output is correct
3 Correct 18 ms 2924 KB Output is correct
4 Correct 20 ms 3052 KB Output is correct
5 Correct 26 ms 3820 KB Output is correct
6 Correct 17 ms 2540 KB Output is correct
7 Correct 4 ms 876 KB Output is correct
8 Correct 17 ms 2540 KB Output is correct
9 Correct 41 ms 5996 KB Output is correct
10 Correct 23 ms 3564 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 14 ms 1900 KB Output is correct
27 Correct 32 ms 5100 KB Output is correct
28 Correct 49 ms 5868 KB Output is correct
29 Correct 165 ms 5228 KB Output is correct
30 Correct 185 ms 5888 KB Output is correct
31 Correct 31 ms 4844 KB Output is correct
32 Correct 2 ms 312 KB Output is correct
33 Correct 31 ms 2668 KB Output is correct
34 Correct 46 ms 5560 KB Output is correct
35 Correct 7 ms 876 KB Output is correct
36 Correct 28 ms 3564 KB Output is correct
37 Correct 42 ms 4204 KB Output is correct
38 Correct 48 ms 5612 KB Output is correct
39 Correct 13 ms 2284 KB Output is correct
40 Correct 2 ms 492 KB Output is correct
41 Correct 148 ms 5668 KB Output is correct
42 Correct 54 ms 6380 KB Output is correct
43 Correct 90 ms 5612 KB Output is correct
44 Correct 54 ms 6124 KB Output is correct
45 Correct 44 ms 6508 KB Output is correct
46 Correct 167 ms 6252 KB Output is correct
47 Correct 39 ms 5740 KB Output is correct
48 Correct 71 ms 5868 KB Output is correct
49 Correct 48 ms 5888 KB Output is correct
50 Correct 731 ms 6124 KB Output is correct
51 Correct 789 ms 6636 KB Output is correct
52 Correct 731 ms 6124 KB Output is correct
53 Correct 773 ms 6508 KB Output is correct
54 Correct 715 ms 5996 KB Output is correct
55 Correct 808 ms 6732 KB Output is correct
56 Correct 699 ms 5996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 30 ms 4332 KB Output is correct
10 Correct 8 ms 1388 KB Output is correct
11 Correct 18 ms 2924 KB Output is correct
12 Correct 20 ms 3052 KB Output is correct
13 Correct 26 ms 3820 KB Output is correct
14 Correct 17 ms 2540 KB Output is correct
15 Correct 4 ms 876 KB Output is correct
16 Correct 17 ms 2540 KB Output is correct
17 Correct 41 ms 5996 KB Output is correct
18 Correct 23 ms 3564 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 492 KB Output is correct
34 Correct 14 ms 1900 KB Output is correct
35 Correct 32 ms 5100 KB Output is correct
36 Correct 49 ms 5868 KB Output is correct
37 Correct 165 ms 5228 KB Output is correct
38 Correct 185 ms 5888 KB Output is correct
39 Correct 31 ms 4844 KB Output is correct
40 Correct 2 ms 312 KB Output is correct
41 Correct 31 ms 2668 KB Output is correct
42 Correct 46 ms 5560 KB Output is correct
43 Correct 7 ms 876 KB Output is correct
44 Correct 28 ms 3564 KB Output is correct
45 Correct 42 ms 4204 KB Output is correct
46 Correct 48 ms 5612 KB Output is correct
47 Correct 13 ms 2284 KB Output is correct
48 Correct 2 ms 492 KB Output is correct
49 Correct 148 ms 5668 KB Output is correct
50 Correct 54 ms 6380 KB Output is correct
51 Correct 90 ms 5612 KB Output is correct
52 Correct 54 ms 6124 KB Output is correct
53 Correct 44 ms 6508 KB Output is correct
54 Correct 167 ms 6252 KB Output is correct
55 Correct 39 ms 5740 KB Output is correct
56 Correct 71 ms 5868 KB Output is correct
57 Correct 48 ms 5888 KB Output is correct
58 Correct 731 ms 6124 KB Output is correct
59 Correct 789 ms 6636 KB Output is correct
60 Correct 731 ms 6124 KB Output is correct
61 Correct 773 ms 6508 KB Output is correct
62 Correct 715 ms 5996 KB Output is correct
63 Correct 808 ms 6732 KB Output is correct
64 Correct 699 ms 5996 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 1 ms 364 KB Output is correct
67 Correct 777 ms 6380 KB Output is correct
68 Correct 775 ms 6380 KB Output is correct
69 Correct 676 ms 5612 KB Output is correct
70 Correct 767 ms 6124 KB Output is correct
71 Correct 745 ms 6124 KB Output is correct
72 Correct 732 ms 5868 KB Output is correct
73 Correct 714 ms 5740 KB Output is correct
74 Correct 765 ms 6252 KB Output is correct
75 Correct 747 ms 5996 KB Output is correct
76 Correct 788 ms 6380 KB Output is correct
77 Correct 135 ms 6636 KB Output is correct
78 Correct 53 ms 5996 KB Output is correct
79 Correct 95 ms 5740 KB Output is correct
80 Correct 100 ms 5996 KB Output is correct
81 Correct 90 ms 5484 KB Output is correct
82 Correct 78 ms 6252 KB Output is correct
83 Correct 61 ms 5868 KB Output is correct
84 Correct 469 ms 6564 KB Output is correct
85 Correct 817 ms 6636 KB Output is correct
86 Correct 2 ms 364 KB Output is correct
87 Correct 1 ms 364 KB Output is correct
88 Correct 839 ms 6808 KB Output is correct
89 Correct 158 ms 1644 KB Output is correct
90 Correct 1 ms 364 KB Output is correct