#include <iostream>
#define int long long int
#define ericxiao ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
const int maxN = 1e5 + 326;
struct Rect{
int l, r, d, u, A;
Rect(){}
Rect(int l, int r, int d, int u): l(l), r(r), d(d), u(u){
A = (r - l + 1) * (u - d + 1);
}
} rects[maxN];
inline bool onDiag(int x, int y, int d){
return (((x % (2 * d)) < d) == ((y % (2 * d)) < d));
}
inline int id(int x, int y, int d){
return x / d * maxN + y / d;
}
int N, K;
inline int check(int d){
//top left is black
//cout << "d = " << d << endl;
int _ans = maxN * maxN, tmp = ((N / d) * (N / d) + 1) / 2 * (d * d);
//cout << "1tmp = " << tmp << endl;
for(int i = 0; i < K; i++){
if(id(rects[i].l, rects[i].u, d) == id(rects[i].r, rects[i].d, d)){
//cout << onDiag(rects[i].l, rects[i].u, d) && onDiag(rects[i].r, rects[i].d, d);
if(onDiag(rects[i].l, rects[i].u, d) && onDiag(rects[i].r, rects[i].d, d)) tmp -= rects[i].A;
else tmp += rects[i].A;
} else {
tmp = maxN * maxN;
break;
}
}
cout << endl;
//cout << "1: " << tmp << endl;
_ans = min(_ans, tmp);
tmp = ((N / d) * (N / d)) / 2 * (d * d);
for(int i = 0; i < K; i++){
if(id(rects[i].l, rects[i].u, d) == id(rects[i].r, rects[i].d, d)){
if(onDiag(rects[i].l, rects[i].u, d) && onDiag(rects[i].r, rects[i].d, d)) tmp += rects[i].A;
else tmp -= rects[i].A;
} else {
tmp = maxN * maxN;
break;
}
}
//cout << "2: " << tmp << endl;
_ans = min(_ans, tmp);
//cout << "d = " << d << ", ans = " << _ans << endl;
return _ans;
//top right is black
}
signed main(){
ericxiao;
cin >> N >> K;
int l, r, d, u;
for(int i = 0; i < K; i++){
cin >> l >> d >> r >> u;
l--; d--; r--; u--;
rects[i] = Rect(l, r, d, u);
//cout << "rects[i] a = " << rects[i].A << endl;
}
int ans = maxN * maxN;
for(int div = 1; div * div <= N; div++){
if(!(N % div)){
ans = min(ans, check(div));
if(div != 1) ans = min(ans, check(N / div));
}
}
cout << ans << endl;
}
/*
*
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
*/
# |
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 |
0 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 |
31 ms |
2816 KB |
Output is correct |
2 |
Correct |
8 ms |
1004 KB |
Output is correct |
3 |
Correct |
19 ms |
1900 KB |
Output is correct |
4 |
Correct |
21 ms |
2156 KB |
Output is correct |
5 |
Correct |
26 ms |
2412 KB |
Output is correct |
6 |
Correct |
17 ms |
1644 KB |
Output is correct |
7 |
Correct |
4 ms |
620 KB |
Output is correct |
8 |
Correct |
21 ms |
1644 KB |
Output is correct |
9 |
Correct |
43 ms |
3820 KB |
Output is correct |
10 |
Correct |
25 ms |
2284 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 |
384 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 |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 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 |
384 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 |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
17 ms |
1388 KB |
Output is correct |
17 |
Correct |
36 ms |
4724 KB |
Output is correct |
18 |
Correct |
60 ms |
5612 KB |
Output is correct |
19 |
Correct |
245 ms |
4972 KB |
Output is correct |
20 |
Correct |
272 ms |
5612 KB |
Output is correct |
21 |
Correct |
34 ms |
4588 KB |
Output is correct |
22 |
Correct |
2 ms |
364 KB |
Output is correct |
23 |
Correct |
41 ms |
2668 KB |
Output is correct |
24 |
Correct |
55 ms |
5100 KB |
Output is correct |
25 |
Correct |
9 ms |
876 KB |
Output is correct |
26 |
Correct |
34 ms |
3436 KB |
Output is correct |
27 |
Correct |
54 ms |
3948 KB |
Output is correct |
28 |
Correct |
59 ms |
5356 KB |
Output is correct |
29 |
Correct |
14 ms |
2156 KB |
Output is correct |
30 |
Correct |
2 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
2816 KB |
Output is correct |
2 |
Correct |
8 ms |
1004 KB |
Output is correct |
3 |
Correct |
19 ms |
1900 KB |
Output is correct |
4 |
Correct |
21 ms |
2156 KB |
Output is correct |
5 |
Correct |
26 ms |
2412 KB |
Output is correct |
6 |
Correct |
17 ms |
1644 KB |
Output is correct |
7 |
Correct |
4 ms |
620 KB |
Output is correct |
8 |
Correct |
21 ms |
1644 KB |
Output is correct |
9 |
Correct |
43 ms |
3820 KB |
Output is correct |
10 |
Correct |
25 ms |
2284 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 |
384 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 |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
2 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 |
17 ms |
1388 KB |
Output is correct |
27 |
Correct |
36 ms |
4724 KB |
Output is correct |
28 |
Correct |
60 ms |
5612 KB |
Output is correct |
29 |
Correct |
245 ms |
4972 KB |
Output is correct |
30 |
Correct |
272 ms |
5612 KB |
Output is correct |
31 |
Correct |
34 ms |
4588 KB |
Output is correct |
32 |
Correct |
2 ms |
364 KB |
Output is correct |
33 |
Correct |
41 ms |
2668 KB |
Output is correct |
34 |
Correct |
55 ms |
5100 KB |
Output is correct |
35 |
Correct |
9 ms |
876 KB |
Output is correct |
36 |
Correct |
34 ms |
3436 KB |
Output is correct |
37 |
Correct |
54 ms |
3948 KB |
Output is correct |
38 |
Correct |
59 ms |
5356 KB |
Output is correct |
39 |
Correct |
14 ms |
2156 KB |
Output is correct |
40 |
Correct |
2 ms |
492 KB |
Output is correct |
41 |
Correct |
220 ms |
4844 KB |
Output is correct |
42 |
Correct |
65 ms |
5356 KB |
Output is correct |
43 |
Correct |
124 ms |
4972 KB |
Output is correct |
44 |
Correct |
65 ms |
5228 KB |
Output is correct |
45 |
Correct |
48 ms |
5484 KB |
Output is correct |
46 |
Correct |
246 ms |
5228 KB |
Output is correct |
47 |
Correct |
43 ms |
4972 KB |
Output is correct |
48 |
Correct |
93 ms |
4972 KB |
Output is correct |
49 |
Correct |
58 ms |
4864 KB |
Output is correct |
50 |
Correct |
1171 ms |
5100 KB |
Output is correct |
51 |
Correct |
1243 ms |
5436 KB |
Output is correct |
52 |
Correct |
1174 ms |
5100 KB |
Output is correct |
53 |
Correct |
1243 ms |
5868 KB |
Output is correct |
54 |
Correct |
1140 ms |
5612 KB |
Output is correct |
55 |
Correct |
1279 ms |
5996 KB |
Output is correct |
56 |
Correct |
1104 ms |
5484 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 |
0 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 |
31 ms |
2816 KB |
Output is correct |
10 |
Correct |
8 ms |
1004 KB |
Output is correct |
11 |
Correct |
19 ms |
1900 KB |
Output is correct |
12 |
Correct |
21 ms |
2156 KB |
Output is correct |
13 |
Correct |
26 ms |
2412 KB |
Output is correct |
14 |
Correct |
17 ms |
1644 KB |
Output is correct |
15 |
Correct |
4 ms |
620 KB |
Output is correct |
16 |
Correct |
21 ms |
1644 KB |
Output is correct |
17 |
Correct |
43 ms |
3820 KB |
Output is correct |
18 |
Correct |
25 ms |
2284 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 |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
384 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 |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
2 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
17 ms |
1388 KB |
Output is correct |
35 |
Correct |
36 ms |
4724 KB |
Output is correct |
36 |
Correct |
60 ms |
5612 KB |
Output is correct |
37 |
Correct |
245 ms |
4972 KB |
Output is correct |
38 |
Correct |
272 ms |
5612 KB |
Output is correct |
39 |
Correct |
34 ms |
4588 KB |
Output is correct |
40 |
Correct |
2 ms |
364 KB |
Output is correct |
41 |
Correct |
41 ms |
2668 KB |
Output is correct |
42 |
Correct |
55 ms |
5100 KB |
Output is correct |
43 |
Correct |
9 ms |
876 KB |
Output is correct |
44 |
Correct |
34 ms |
3436 KB |
Output is correct |
45 |
Correct |
54 ms |
3948 KB |
Output is correct |
46 |
Correct |
59 ms |
5356 KB |
Output is correct |
47 |
Correct |
14 ms |
2156 KB |
Output is correct |
48 |
Correct |
2 ms |
492 KB |
Output is correct |
49 |
Correct |
220 ms |
4844 KB |
Output is correct |
50 |
Correct |
65 ms |
5356 KB |
Output is correct |
51 |
Correct |
124 ms |
4972 KB |
Output is correct |
52 |
Correct |
65 ms |
5228 KB |
Output is correct |
53 |
Correct |
48 ms |
5484 KB |
Output is correct |
54 |
Correct |
246 ms |
5228 KB |
Output is correct |
55 |
Correct |
43 ms |
4972 KB |
Output is correct |
56 |
Correct |
93 ms |
4972 KB |
Output is correct |
57 |
Correct |
58 ms |
4864 KB |
Output is correct |
58 |
Correct |
1171 ms |
5100 KB |
Output is correct |
59 |
Correct |
1243 ms |
5436 KB |
Output is correct |
60 |
Correct |
1174 ms |
5100 KB |
Output is correct |
61 |
Correct |
1243 ms |
5868 KB |
Output is correct |
62 |
Correct |
1140 ms |
5612 KB |
Output is correct |
63 |
Correct |
1279 ms |
5996 KB |
Output is correct |
64 |
Correct |
1104 ms |
5484 KB |
Output is correct |
65 |
Correct |
1 ms |
364 KB |
Output is correct |
66 |
Incorrect |
2 ms |
364 KB |
Output isn't correct |
67 |
Halted |
0 ms |
0 KB |
- |