#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 1;
#define int long long
int odd[N][101],even[N][101],it = 0;
ll col_eq(int k,int x,int y,int x1,int y1){
ll ret = (odd[x1][k] - odd[x - 1][k]) * (odd[y1][k] - odd[y - 1][k]);
ret += (even[x1][k] - even[x - 1][k]) *1ll* (even[y1][k] - even[y - 1][k]);
return ret;
}
ll col_non_eq(int k,int x,int y,int x1,int y1){
ll ret = (odd[x1][k] - odd[x - 1][k]) * (even[y1][k] - even[y - 1][k]);
ret += (even[x1][k] - even[x - 1][k]) *1ll* (odd[y1][k] - odd[y - 1][k]);
return ret;
}
vector<pair<pair<int,int>,pair<int,int>>> a;
ll n,k;
int get(ll del,ll i){
ll res1 = 0,res2 = 0;
for(auto [x,y]:a){
res1 += col_eq(i,x.first,x.second,y.first,y.second);
res2 += col_non_eq(i,x.first,x.second,y.first,y.second);
}
res1 = ((n * n / del / del)+1) / 2 * (del * del) + res2 - res1;
// cout << ((n * n / del / del) + 1) / 2 * del * del << '\n';
return min(res1,n * n - res1);
}
void test(){
cin >> n >> k;
for(int i = 1;i <= k;i++){
int x,y,x1,y1;
cin >> x >> y >> x1 >> y1;
a.push_back({{x,y},{x1,y1}});
}
ll res = 1e10;
for(int i = 1;i < n;i++){
if(n % i == 0){
for(int j = 1;j <= n;j++){
int x = (j - 1) / i;
odd[j][it] = odd[j - 1][it];
even[j][it] = even[j - 1][it];
if(x & 1){
odd[j][it]++;
}else{
even[j][it]++;
}
}
it++;
}
}
it = 0;
for(int i = 1;i < n;i++){
if(n % i == 0){
res = min(res,1ll*get(i,it));
it++;
}
}
cout << res;
}
main(){
ios_base::sync_with_stdio(0);cin.tie(0);
test();
}
Compilation message
chessboard.cpp:62:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
62 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
424 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
103856 KB |
Output is correct |
2 |
Correct |
8 ms |
25300 KB |
Output is correct |
3 |
Correct |
37 ms |
137416 KB |
Output is correct |
4 |
Correct |
13 ms |
8144 KB |
Output is correct |
5 |
Correct |
29 ms |
95180 KB |
Output is correct |
6 |
Correct |
21 ms |
81616 KB |
Output is correct |
7 |
Correct |
9 ms |
39252 KB |
Output is correct |
8 |
Correct |
22 ms |
81620 KB |
Output is correct |
9 |
Correct |
34 ms |
56004 KB |
Output is correct |
10 |
Correct |
23 ms |
66004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
604 KB |
Output is correct |
12 |
Correct |
0 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
604 KB |
Output is correct |
12 |
Correct |
0 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
488 KB |
Output is correct |
16 |
Correct |
8 ms |
4976 KB |
Output is correct |
17 |
Correct |
20 ms |
7632 KB |
Output is correct |
18 |
Correct |
25 ms |
8460 KB |
Output is correct |
19 |
Correct |
42 ms |
7608 KB |
Output is correct |
20 |
Correct |
45 ms |
8316 KB |
Output is correct |
21 |
Correct |
19 ms |
7624 KB |
Output is correct |
22 |
Correct |
1 ms |
3420 KB |
Output is correct |
23 |
Correct |
13 ms |
5444 KB |
Output is correct |
24 |
Correct |
22 ms |
8648 KB |
Output is correct |
25 |
Correct |
4 ms |
3800 KB |
Output is correct |
26 |
Correct |
15 ms |
6144 KB |
Output is correct |
27 |
Correct |
19 ms |
7376 KB |
Output is correct |
28 |
Correct |
24 ms |
8916 KB |
Output is correct |
29 |
Correct |
9 ms |
5076 KB |
Output is correct |
30 |
Correct |
2 ms |
3676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
103856 KB |
Output is correct |
2 |
Correct |
8 ms |
25300 KB |
Output is correct |
3 |
Correct |
37 ms |
137416 KB |
Output is correct |
4 |
Correct |
13 ms |
8144 KB |
Output is correct |
5 |
Correct |
29 ms |
95180 KB |
Output is correct |
6 |
Correct |
21 ms |
81616 KB |
Output is correct |
7 |
Correct |
9 ms |
39252 KB |
Output is correct |
8 |
Correct |
22 ms |
81620 KB |
Output is correct |
9 |
Correct |
34 ms |
56004 KB |
Output is correct |
10 |
Correct |
23 ms |
66004 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
0 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
604 KB |
Output is correct |
22 |
Correct |
0 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
488 KB |
Output is correct |
26 |
Correct |
8 ms |
4976 KB |
Output is correct |
27 |
Correct |
20 ms |
7632 KB |
Output is correct |
28 |
Correct |
25 ms |
8460 KB |
Output is correct |
29 |
Correct |
42 ms |
7608 KB |
Output is correct |
30 |
Correct |
45 ms |
8316 KB |
Output is correct |
31 |
Correct |
19 ms |
7624 KB |
Output is correct |
32 |
Correct |
1 ms |
3420 KB |
Output is correct |
33 |
Correct |
13 ms |
5444 KB |
Output is correct |
34 |
Correct |
22 ms |
8648 KB |
Output is correct |
35 |
Correct |
4 ms |
3800 KB |
Output is correct |
36 |
Correct |
15 ms |
6144 KB |
Output is correct |
37 |
Correct |
19 ms |
7376 KB |
Output is correct |
38 |
Correct |
24 ms |
8916 KB |
Output is correct |
39 |
Correct |
9 ms |
5076 KB |
Output is correct |
40 |
Correct |
2 ms |
3676 KB |
Output is correct |
41 |
Correct |
210 ms |
163692 KB |
Output is correct |
42 |
Correct |
66 ms |
164552 KB |
Output is correct |
43 |
Correct |
123 ms |
164444 KB |
Output is correct |
44 |
Correct |
64 ms |
164028 KB |
Output is correct |
45 |
Correct |
52 ms |
163992 KB |
Output is correct |
46 |
Correct |
234 ms |
164288 KB |
Output is correct |
47 |
Correct |
48 ms |
162784 KB |
Output is correct |
48 |
Correct |
91 ms |
164292 KB |
Output is correct |
49 |
Correct |
63 ms |
163212 KB |
Output is correct |
50 |
Correct |
896 ms |
138688 KB |
Output is correct |
51 |
Correct |
936 ms |
138436 KB |
Output is correct |
52 |
Correct |
919 ms |
138432 KB |
Output is correct |
53 |
Correct |
930 ms |
139056 KB |
Output is correct |
54 |
Correct |
858 ms |
138436 KB |
Output is correct |
55 |
Correct |
965 ms |
138696 KB |
Output is correct |
56 |
Correct |
843 ms |
138948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
424 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
43 ms |
103856 KB |
Output is correct |
10 |
Correct |
8 ms |
25300 KB |
Output is correct |
11 |
Correct |
37 ms |
137416 KB |
Output is correct |
12 |
Correct |
13 ms |
8144 KB |
Output is correct |
13 |
Correct |
29 ms |
95180 KB |
Output is correct |
14 |
Correct |
21 ms |
81616 KB |
Output is correct |
15 |
Correct |
9 ms |
39252 KB |
Output is correct |
16 |
Correct |
22 ms |
81620 KB |
Output is correct |
17 |
Correct |
34 ms |
56004 KB |
Output is correct |
18 |
Correct |
23 ms |
66004 KB |
Output is correct |
19 |
Correct |
1 ms |
600 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
600 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
0 ms |
604 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
604 KB |
Output is correct |
30 |
Correct |
0 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
604 KB |
Output is correct |
32 |
Correct |
1 ms |
604 KB |
Output is correct |
33 |
Correct |
1 ms |
488 KB |
Output is correct |
34 |
Correct |
8 ms |
4976 KB |
Output is correct |
35 |
Correct |
20 ms |
7632 KB |
Output is correct |
36 |
Correct |
25 ms |
8460 KB |
Output is correct |
37 |
Correct |
42 ms |
7608 KB |
Output is correct |
38 |
Correct |
45 ms |
8316 KB |
Output is correct |
39 |
Correct |
19 ms |
7624 KB |
Output is correct |
40 |
Correct |
1 ms |
3420 KB |
Output is correct |
41 |
Correct |
13 ms |
5444 KB |
Output is correct |
42 |
Correct |
22 ms |
8648 KB |
Output is correct |
43 |
Correct |
4 ms |
3800 KB |
Output is correct |
44 |
Correct |
15 ms |
6144 KB |
Output is correct |
45 |
Correct |
19 ms |
7376 KB |
Output is correct |
46 |
Correct |
24 ms |
8916 KB |
Output is correct |
47 |
Correct |
9 ms |
5076 KB |
Output is correct |
48 |
Correct |
2 ms |
3676 KB |
Output is correct |
49 |
Correct |
210 ms |
163692 KB |
Output is correct |
50 |
Correct |
66 ms |
164552 KB |
Output is correct |
51 |
Correct |
123 ms |
164444 KB |
Output is correct |
52 |
Correct |
64 ms |
164028 KB |
Output is correct |
53 |
Correct |
52 ms |
163992 KB |
Output is correct |
54 |
Correct |
234 ms |
164288 KB |
Output is correct |
55 |
Correct |
48 ms |
162784 KB |
Output is correct |
56 |
Correct |
91 ms |
164292 KB |
Output is correct |
57 |
Correct |
63 ms |
163212 KB |
Output is correct |
58 |
Correct |
896 ms |
138688 KB |
Output is correct |
59 |
Correct |
936 ms |
138436 KB |
Output is correct |
60 |
Correct |
919 ms |
138432 KB |
Output is correct |
61 |
Correct |
930 ms |
139056 KB |
Output is correct |
62 |
Correct |
858 ms |
138436 KB |
Output is correct |
63 |
Correct |
965 ms |
138696 KB |
Output is correct |
64 |
Correct |
843 ms |
138948 KB |
Output is correct |
65 |
Correct |
0 ms |
348 KB |
Output is correct |
66 |
Correct |
0 ms |
348 KB |
Output is correct |
67 |
Correct |
860 ms |
139076 KB |
Output is correct |
68 |
Correct |
870 ms |
138184 KB |
Output is correct |
69 |
Correct |
693 ms |
138436 KB |
Output is correct |
70 |
Incorrect |
509 ms |
138180 KB |
Output isn't correct |
71 |
Halted |
0 ms |
0 KB |
- |