#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 12;
#define int long long
map<int,int> odd[N],even[N];
ll col_eq(int k,int x,int y,int x1,int y1){
int ret = 0;
for(int i = x;i <= x1;i++){
for(int j = y;j <= y1;j++){
if(((i + k - 1) / k) % 2 == ((j + k - 1) / k) % 2){
ret++;
}
}
}
// 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){
return (x1 - x + 1) *1ll* (y1 - y + 1) - col_eq(k,x,y,x1,y1);
}
vector<pair<pair<int,int>,pair<int,int>>> a;
ll n,k;
int get(ll del){
ll res1 = 0,res2 = 0;
for(auto [x,y]:a){
res1 += col_eq(del,x.first,x.second,y.first,y.second);
res2 += col_non_eq(del,x.first,x.second,y.first,y.second);
}
ll x = res1;
res1 = ((n * n / del / del) + 1) / 2 * (del * del) - res1 + res2;
res2 = ((n * n / del / del)) / 2 * (del * del) + x - res2;
// cout << ((n * n / del / del) + 1) / 2 * del * del - res2 << '\n';
return min(res1,res2);
}
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 + i - 1) / i;
odd[j][i] = odd[j - 1][i];
even[j][i] = even[j - 1][i];
if(x & 1){
odd[j][i]++;
}else{
even[j][i]++;
}
}
}
}
for(int i = 1;i < n;i++){
if(n % i == 0){
res = min(res,1ll*get(i));
}
}
cout << res;
}
main(){
ios_base::sync_with_stdio(0);cin.tie(0);
test();
}
Compilation message
chessboard.cpp:66:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
66 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
94300 KB |
Output is correct |
2 |
Correct |
19 ms |
94300 KB |
Output is correct |
3 |
Correct |
18 ms |
94300 KB |
Output is correct |
4 |
Correct |
20 ms |
94216 KB |
Output is correct |
5 |
Correct |
19 ms |
94204 KB |
Output is correct |
6 |
Correct |
19 ms |
94300 KB |
Output is correct |
7 |
Correct |
19 ms |
94300 KB |
Output is correct |
8 |
Correct |
22 ms |
94300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
103880 KB |
Output is correct |
2 |
Correct |
25 ms |
96472 KB |
Output is correct |
3 |
Correct |
43 ms |
105896 KB |
Output is correct |
4 |
Correct |
30 ms |
96472 KB |
Output is correct |
5 |
Correct |
41 ms |
103124 KB |
Output is correct |
6 |
Correct |
36 ms |
101320 KB |
Output is correct |
7 |
Correct |
25 ms |
97348 KB |
Output is correct |
8 |
Correct |
39 ms |
101580 KB |
Output is correct |
9 |
Correct |
47 ms |
102148 KB |
Output is correct |
10 |
Correct |
37 ms |
100564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
94292 KB |
Output is correct |
2 |
Correct |
19 ms |
94300 KB |
Output is correct |
3 |
Correct |
19 ms |
94384 KB |
Output is correct |
4 |
Correct |
20 ms |
94296 KB |
Output is correct |
5 |
Correct |
18 ms |
94300 KB |
Output is correct |
6 |
Correct |
19 ms |
94300 KB |
Output is correct |
7 |
Correct |
19 ms |
94304 KB |
Output is correct |
8 |
Correct |
19 ms |
94300 KB |
Output is correct |
9 |
Correct |
18 ms |
94300 KB |
Output is correct |
10 |
Correct |
19 ms |
94300 KB |
Output is correct |
11 |
Correct |
19 ms |
94296 KB |
Output is correct |
12 |
Correct |
19 ms |
94296 KB |
Output is correct |
13 |
Correct |
20 ms |
94296 KB |
Output is correct |
14 |
Correct |
19 ms |
94300 KB |
Output is correct |
15 |
Correct |
19 ms |
94300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
94292 KB |
Output is correct |
2 |
Correct |
19 ms |
94300 KB |
Output is correct |
3 |
Correct |
19 ms |
94384 KB |
Output is correct |
4 |
Correct |
20 ms |
94296 KB |
Output is correct |
5 |
Correct |
18 ms |
94300 KB |
Output is correct |
6 |
Correct |
19 ms |
94300 KB |
Output is correct |
7 |
Correct |
19 ms |
94304 KB |
Output is correct |
8 |
Correct |
19 ms |
94300 KB |
Output is correct |
9 |
Correct |
18 ms |
94300 KB |
Output is correct |
10 |
Correct |
19 ms |
94300 KB |
Output is correct |
11 |
Correct |
19 ms |
94296 KB |
Output is correct |
12 |
Correct |
19 ms |
94296 KB |
Output is correct |
13 |
Correct |
20 ms |
94296 KB |
Output is correct |
14 |
Correct |
19 ms |
94300 KB |
Output is correct |
15 |
Correct |
19 ms |
94300 KB |
Output is correct |
16 |
Correct |
26 ms |
95452 KB |
Output is correct |
17 |
Correct |
38 ms |
99900 KB |
Output is correct |
18 |
Correct |
45 ms |
98504 KB |
Output is correct |
19 |
Correct |
92 ms |
101316 KB |
Output is correct |
20 |
Correct |
99 ms |
100552 KB |
Output is correct |
21 |
Correct |
38 ms |
100620 KB |
Output is correct |
22 |
Correct |
23 ms |
96148 KB |
Output is correct |
23 |
Correct |
38 ms |
96516 KB |
Output is correct |
24 |
Correct |
44 ms |
100128 KB |
Output is correct |
25 |
Correct |
23 ms |
95448 KB |
Output is correct |
26 |
Correct |
35 ms |
96472 KB |
Output is correct |
27 |
Correct |
47 ms |
98764 KB |
Output is correct |
28 |
Correct |
46 ms |
100300 KB |
Output is correct |
29 |
Correct |
27 ms |
96464 KB |
Output is correct |
30 |
Correct |
20 ms |
94808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
103880 KB |
Output is correct |
2 |
Correct |
25 ms |
96472 KB |
Output is correct |
3 |
Correct |
43 ms |
105896 KB |
Output is correct |
4 |
Correct |
30 ms |
96472 KB |
Output is correct |
5 |
Correct |
41 ms |
103124 KB |
Output is correct |
6 |
Correct |
36 ms |
101320 KB |
Output is correct |
7 |
Correct |
25 ms |
97348 KB |
Output is correct |
8 |
Correct |
39 ms |
101580 KB |
Output is correct |
9 |
Correct |
47 ms |
102148 KB |
Output is correct |
10 |
Correct |
37 ms |
100564 KB |
Output is correct |
11 |
Correct |
22 ms |
94292 KB |
Output is correct |
12 |
Correct |
19 ms |
94300 KB |
Output is correct |
13 |
Correct |
19 ms |
94384 KB |
Output is correct |
14 |
Correct |
20 ms |
94296 KB |
Output is correct |
15 |
Correct |
18 ms |
94300 KB |
Output is correct |
16 |
Correct |
19 ms |
94300 KB |
Output is correct |
17 |
Correct |
19 ms |
94304 KB |
Output is correct |
18 |
Correct |
19 ms |
94300 KB |
Output is correct |
19 |
Correct |
18 ms |
94300 KB |
Output is correct |
20 |
Correct |
19 ms |
94300 KB |
Output is correct |
21 |
Correct |
19 ms |
94296 KB |
Output is correct |
22 |
Correct |
19 ms |
94296 KB |
Output is correct |
23 |
Correct |
20 ms |
94296 KB |
Output is correct |
24 |
Correct |
19 ms |
94300 KB |
Output is correct |
25 |
Correct |
19 ms |
94300 KB |
Output is correct |
26 |
Correct |
26 ms |
95452 KB |
Output is correct |
27 |
Correct |
38 ms |
99900 KB |
Output is correct |
28 |
Correct |
45 ms |
98504 KB |
Output is correct |
29 |
Correct |
92 ms |
101316 KB |
Output is correct |
30 |
Correct |
99 ms |
100552 KB |
Output is correct |
31 |
Correct |
38 ms |
100620 KB |
Output is correct |
32 |
Correct |
23 ms |
96148 KB |
Output is correct |
33 |
Correct |
38 ms |
96516 KB |
Output is correct |
34 |
Correct |
44 ms |
100128 KB |
Output is correct |
35 |
Correct |
23 ms |
95448 KB |
Output is correct |
36 |
Correct |
35 ms |
96472 KB |
Output is correct |
37 |
Correct |
47 ms |
98764 KB |
Output is correct |
38 |
Correct |
46 ms |
100300 KB |
Output is correct |
39 |
Correct |
27 ms |
96464 KB |
Output is correct |
40 |
Correct |
20 ms |
94808 KB |
Output is correct |
41 |
Runtime error |
210 ms |
262144 KB |
Execution killed with signal 9 |
42 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
94300 KB |
Output is correct |
2 |
Correct |
19 ms |
94300 KB |
Output is correct |
3 |
Correct |
18 ms |
94300 KB |
Output is correct |
4 |
Correct |
20 ms |
94216 KB |
Output is correct |
5 |
Correct |
19 ms |
94204 KB |
Output is correct |
6 |
Correct |
19 ms |
94300 KB |
Output is correct |
7 |
Correct |
19 ms |
94300 KB |
Output is correct |
8 |
Correct |
22 ms |
94300 KB |
Output is correct |
9 |
Correct |
44 ms |
103880 KB |
Output is correct |
10 |
Correct |
25 ms |
96472 KB |
Output is correct |
11 |
Correct |
43 ms |
105896 KB |
Output is correct |
12 |
Correct |
30 ms |
96472 KB |
Output is correct |
13 |
Correct |
41 ms |
103124 KB |
Output is correct |
14 |
Correct |
36 ms |
101320 KB |
Output is correct |
15 |
Correct |
25 ms |
97348 KB |
Output is correct |
16 |
Correct |
39 ms |
101580 KB |
Output is correct |
17 |
Correct |
47 ms |
102148 KB |
Output is correct |
18 |
Correct |
37 ms |
100564 KB |
Output is correct |
19 |
Correct |
22 ms |
94292 KB |
Output is correct |
20 |
Correct |
19 ms |
94300 KB |
Output is correct |
21 |
Correct |
19 ms |
94384 KB |
Output is correct |
22 |
Correct |
20 ms |
94296 KB |
Output is correct |
23 |
Correct |
18 ms |
94300 KB |
Output is correct |
24 |
Correct |
19 ms |
94300 KB |
Output is correct |
25 |
Correct |
19 ms |
94304 KB |
Output is correct |
26 |
Correct |
19 ms |
94300 KB |
Output is correct |
27 |
Correct |
18 ms |
94300 KB |
Output is correct |
28 |
Correct |
19 ms |
94300 KB |
Output is correct |
29 |
Correct |
19 ms |
94296 KB |
Output is correct |
30 |
Correct |
19 ms |
94296 KB |
Output is correct |
31 |
Correct |
20 ms |
94296 KB |
Output is correct |
32 |
Correct |
19 ms |
94300 KB |
Output is correct |
33 |
Correct |
19 ms |
94300 KB |
Output is correct |
34 |
Correct |
26 ms |
95452 KB |
Output is correct |
35 |
Correct |
38 ms |
99900 KB |
Output is correct |
36 |
Correct |
45 ms |
98504 KB |
Output is correct |
37 |
Correct |
92 ms |
101316 KB |
Output is correct |
38 |
Correct |
99 ms |
100552 KB |
Output is correct |
39 |
Correct |
38 ms |
100620 KB |
Output is correct |
40 |
Correct |
23 ms |
96148 KB |
Output is correct |
41 |
Correct |
38 ms |
96516 KB |
Output is correct |
42 |
Correct |
44 ms |
100128 KB |
Output is correct |
43 |
Correct |
23 ms |
95448 KB |
Output is correct |
44 |
Correct |
35 ms |
96472 KB |
Output is correct |
45 |
Correct |
47 ms |
98764 KB |
Output is correct |
46 |
Correct |
46 ms |
100300 KB |
Output is correct |
47 |
Correct |
27 ms |
96464 KB |
Output is correct |
48 |
Correct |
20 ms |
94808 KB |
Output is correct |
49 |
Runtime error |
210 ms |
262144 KB |
Execution killed with signal 9 |
50 |
Halted |
0 ms |
0 KB |
- |