#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
struct Rec {
int x1, y1, x2, y2;
} rec[N];
int n, m;
long long res = 1e18;
void cal(int x, int l, int r, int *cnt) {
cnt[0] = cnt[1] = 0;
if (l / x != r / x) {
cnt[0] += ( (r / x - 1) / 2 - l / x / 2 ) * x;
if (r / x % 2 == 0) cnt[0] += r - r / x * x + 1;
if (l / x % 2 == 0) cnt[0] += (l / x + 1) * x - l;
}
else {
if (l / x % 2 == 0) cnt[0] += r - l + 1;
}
cnt[1] = r - l + 1 - cnt[0];
// cout << "# " << cnt[0] << ' ' << cnt[1] << '\n';
}
void solve(int fix) {
long long val1 = 0, val2 = 0;
// change all white -> black
val1 = 1LL * (n / fix) * (n / fix) / 2 * fix * fix;
val2 = 1LL * n * n - val1;
// cout << "#val " << val1 << ' ' << val2 << '\n';
for (int i = 1; i <= m; ++i) {
int cntx[2], cnty[2];
// cout << "#X\n";
cal(fix, rec[i].x1, rec[i].x2, cntx);
// cout << "#Y\n";
cal(fix, rec[i].y1, rec[i].y2, cnty);
val1 += 1LL * cntx[0] * cnty[0] + 1LL * cntx[1] * cnty[1]; // black -> white
val1 -= 1LL * cntx[0] * cnty[1] + 1LL * cntx[1] * cnty[0]; // black -> black
val2 += 1LL * cntx[0] * cnty[1] + 1LL * cntx[1] * cnty[0]; // black -> white
val2 -= 1LL * cntx[0] * cnty[0] + 1LL * cntx[1] * cnty[1]; // black -> black
}
// cout << "#at " << fix << ' ' << val1 << ' ' << val2 << '\n';
res = min(res, min(val1, val2));
}
int main() {
ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= m; ++i) {
cin >> rec[i].x1 >> rec[i].y1 >> rec[i].x2 >> rec[i].y2;
rec[i].x1--, rec[i].x2--, rec[i].y1--, rec[i].y2--;
}
// solve(2);
for (int i = 1; i < n; ++i) {
if (n % i == 0) solve(i);
}
cout << res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
248 KB |
Output is correct |
2 |
Correct |
1 ms |
484 KB |
Output is correct |
3 |
Correct |
1 ms |
568 KB |
Output is correct |
4 |
Correct |
1 ms |
568 KB |
Output is correct |
5 |
Correct |
1 ms |
648 KB |
Output is correct |
6 |
Correct |
1 ms |
648 KB |
Output is correct |
7 |
Correct |
1 ms |
648 KB |
Output is correct |
8 |
Correct |
1 ms |
648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
3052 KB |
Output is correct |
2 |
Correct |
9 ms |
3052 KB |
Output is correct |
3 |
Correct |
19 ms |
4060 KB |
Output is correct |
4 |
Correct |
22 ms |
5052 KB |
Output is correct |
5 |
Correct |
24 ms |
6392 KB |
Output is correct |
6 |
Correct |
18 ms |
6932 KB |
Output is correct |
7 |
Correct |
5 ms |
6932 KB |
Output is correct |
8 |
Correct |
17 ms |
8048 KB |
Output is correct |
9 |
Correct |
43 ms |
10872 KB |
Output is correct |
10 |
Correct |
23 ms |
11460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
11460 KB |
Output is correct |
2 |
Correct |
1 ms |
11460 KB |
Output is correct |
3 |
Correct |
1 ms |
11460 KB |
Output is correct |
4 |
Correct |
2 ms |
11460 KB |
Output is correct |
5 |
Correct |
2 ms |
11460 KB |
Output is correct |
6 |
Correct |
2 ms |
11460 KB |
Output is correct |
7 |
Correct |
2 ms |
11460 KB |
Output is correct |
8 |
Correct |
2 ms |
11460 KB |
Output is correct |
9 |
Correct |
2 ms |
11460 KB |
Output is correct |
10 |
Correct |
2 ms |
11460 KB |
Output is correct |
11 |
Correct |
2 ms |
11460 KB |
Output is correct |
12 |
Correct |
2 ms |
11460 KB |
Output is correct |
13 |
Correct |
2 ms |
11460 KB |
Output is correct |
14 |
Correct |
2 ms |
11460 KB |
Output is correct |
15 |
Correct |
2 ms |
11460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
11460 KB |
Output is correct |
2 |
Correct |
1 ms |
11460 KB |
Output is correct |
3 |
Correct |
1 ms |
11460 KB |
Output is correct |
4 |
Correct |
2 ms |
11460 KB |
Output is correct |
5 |
Correct |
2 ms |
11460 KB |
Output is correct |
6 |
Correct |
2 ms |
11460 KB |
Output is correct |
7 |
Correct |
2 ms |
11460 KB |
Output is correct |
8 |
Correct |
2 ms |
11460 KB |
Output is correct |
9 |
Correct |
2 ms |
11460 KB |
Output is correct |
10 |
Correct |
2 ms |
11460 KB |
Output is correct |
11 |
Correct |
2 ms |
11460 KB |
Output is correct |
12 |
Correct |
2 ms |
11460 KB |
Output is correct |
13 |
Correct |
2 ms |
11460 KB |
Output is correct |
14 |
Correct |
2 ms |
11460 KB |
Output is correct |
15 |
Correct |
2 ms |
11460 KB |
Output is correct |
16 |
Correct |
13 ms |
11744 KB |
Output is correct |
17 |
Correct |
33 ms |
13996 KB |
Output is correct |
18 |
Correct |
46 ms |
15724 KB |
Output is correct |
19 |
Correct |
118 ms |
17092 KB |
Output is correct |
20 |
Correct |
128 ms |
18900 KB |
Output is correct |
21 |
Correct |
33 ms |
19856 KB |
Output is correct |
22 |
Correct |
2 ms |
19856 KB |
Output is correct |
23 |
Correct |
30 ms |
19896 KB |
Output is correct |
24 |
Correct |
48 ms |
22256 KB |
Output is correct |
25 |
Correct |
9 ms |
22256 KB |
Output is correct |
26 |
Correct |
31 ms |
22712 KB |
Output is correct |
27 |
Correct |
36 ms |
23984 KB |
Output is correct |
28 |
Correct |
43 ms |
25980 KB |
Output is correct |
29 |
Correct |
14 ms |
25980 KB |
Output is correct |
30 |
Correct |
3 ms |
25980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
3052 KB |
Output is correct |
2 |
Correct |
9 ms |
3052 KB |
Output is correct |
3 |
Correct |
19 ms |
4060 KB |
Output is correct |
4 |
Correct |
22 ms |
5052 KB |
Output is correct |
5 |
Correct |
24 ms |
6392 KB |
Output is correct |
6 |
Correct |
18 ms |
6932 KB |
Output is correct |
7 |
Correct |
5 ms |
6932 KB |
Output is correct |
8 |
Correct |
17 ms |
8048 KB |
Output is correct |
9 |
Correct |
43 ms |
10872 KB |
Output is correct |
10 |
Correct |
23 ms |
11460 KB |
Output is correct |
11 |
Correct |
2 ms |
11460 KB |
Output is correct |
12 |
Correct |
1 ms |
11460 KB |
Output is correct |
13 |
Correct |
1 ms |
11460 KB |
Output is correct |
14 |
Correct |
2 ms |
11460 KB |
Output is correct |
15 |
Correct |
2 ms |
11460 KB |
Output is correct |
16 |
Correct |
2 ms |
11460 KB |
Output is correct |
17 |
Correct |
2 ms |
11460 KB |
Output is correct |
18 |
Correct |
2 ms |
11460 KB |
Output is correct |
19 |
Correct |
2 ms |
11460 KB |
Output is correct |
20 |
Correct |
2 ms |
11460 KB |
Output is correct |
21 |
Correct |
2 ms |
11460 KB |
Output is correct |
22 |
Correct |
2 ms |
11460 KB |
Output is correct |
23 |
Correct |
2 ms |
11460 KB |
Output is correct |
24 |
Correct |
2 ms |
11460 KB |
Output is correct |
25 |
Correct |
2 ms |
11460 KB |
Output is correct |
26 |
Correct |
13 ms |
11744 KB |
Output is correct |
27 |
Correct |
33 ms |
13996 KB |
Output is correct |
28 |
Correct |
46 ms |
15724 KB |
Output is correct |
29 |
Correct |
118 ms |
17092 KB |
Output is correct |
30 |
Correct |
128 ms |
18900 KB |
Output is correct |
31 |
Correct |
33 ms |
19856 KB |
Output is correct |
32 |
Correct |
2 ms |
19856 KB |
Output is correct |
33 |
Correct |
30 ms |
19896 KB |
Output is correct |
34 |
Correct |
48 ms |
22256 KB |
Output is correct |
35 |
Correct |
9 ms |
22256 KB |
Output is correct |
36 |
Correct |
31 ms |
22712 KB |
Output is correct |
37 |
Correct |
36 ms |
23984 KB |
Output is correct |
38 |
Correct |
43 ms |
25980 KB |
Output is correct |
39 |
Correct |
14 ms |
25980 KB |
Output is correct |
40 |
Correct |
3 ms |
25980 KB |
Output is correct |
41 |
Correct |
102 ms |
28384 KB |
Output is correct |
42 |
Correct |
48 ms |
30792 KB |
Output is correct |
43 |
Correct |
68 ms |
32668 KB |
Output is correct |
44 |
Correct |
50 ms |
34944 KB |
Output is correct |
45 |
Correct |
47 ms |
37372 KB |
Output is correct |
46 |
Correct |
111 ms |
39468 KB |
Output is correct |
47 |
Correct |
47 ms |
41452 KB |
Output is correct |
48 |
Correct |
58 ms |
43760 KB |
Output is correct |
49 |
Correct |
43 ms |
45592 KB |
Output is correct |
50 |
Correct |
461 ms |
47968 KB |
Output is correct |
51 |
Correct |
477 ms |
50316 KB |
Output is correct |
52 |
Correct |
445 ms |
52228 KB |
Output is correct |
53 |
Correct |
474 ms |
54764 KB |
Output is correct |
54 |
Correct |
450 ms |
56820 KB |
Output is correct |
55 |
Correct |
492 ms |
59328 KB |
Output is correct |
56 |
Correct |
436 ms |
61324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
248 KB |
Output is correct |
2 |
Correct |
1 ms |
484 KB |
Output is correct |
3 |
Correct |
1 ms |
568 KB |
Output is correct |
4 |
Correct |
1 ms |
568 KB |
Output is correct |
5 |
Correct |
1 ms |
648 KB |
Output is correct |
6 |
Correct |
1 ms |
648 KB |
Output is correct |
7 |
Correct |
1 ms |
648 KB |
Output is correct |
8 |
Correct |
1 ms |
648 KB |
Output is correct |
9 |
Correct |
28 ms |
3052 KB |
Output is correct |
10 |
Correct |
9 ms |
3052 KB |
Output is correct |
11 |
Correct |
19 ms |
4060 KB |
Output is correct |
12 |
Correct |
22 ms |
5052 KB |
Output is correct |
13 |
Correct |
24 ms |
6392 KB |
Output is correct |
14 |
Correct |
18 ms |
6932 KB |
Output is correct |
15 |
Correct |
5 ms |
6932 KB |
Output is correct |
16 |
Correct |
17 ms |
8048 KB |
Output is correct |
17 |
Correct |
43 ms |
10872 KB |
Output is correct |
18 |
Correct |
23 ms |
11460 KB |
Output is correct |
19 |
Correct |
2 ms |
11460 KB |
Output is correct |
20 |
Correct |
1 ms |
11460 KB |
Output is correct |
21 |
Correct |
1 ms |
11460 KB |
Output is correct |
22 |
Correct |
2 ms |
11460 KB |
Output is correct |
23 |
Correct |
2 ms |
11460 KB |
Output is correct |
24 |
Correct |
2 ms |
11460 KB |
Output is correct |
25 |
Correct |
2 ms |
11460 KB |
Output is correct |
26 |
Correct |
2 ms |
11460 KB |
Output is correct |
27 |
Correct |
2 ms |
11460 KB |
Output is correct |
28 |
Correct |
2 ms |
11460 KB |
Output is correct |
29 |
Correct |
2 ms |
11460 KB |
Output is correct |
30 |
Correct |
2 ms |
11460 KB |
Output is correct |
31 |
Correct |
2 ms |
11460 KB |
Output is correct |
32 |
Correct |
2 ms |
11460 KB |
Output is correct |
33 |
Correct |
2 ms |
11460 KB |
Output is correct |
34 |
Correct |
13 ms |
11744 KB |
Output is correct |
35 |
Correct |
33 ms |
13996 KB |
Output is correct |
36 |
Correct |
46 ms |
15724 KB |
Output is correct |
37 |
Correct |
118 ms |
17092 KB |
Output is correct |
38 |
Correct |
128 ms |
18900 KB |
Output is correct |
39 |
Correct |
33 ms |
19856 KB |
Output is correct |
40 |
Correct |
2 ms |
19856 KB |
Output is correct |
41 |
Correct |
30 ms |
19896 KB |
Output is correct |
42 |
Correct |
48 ms |
22256 KB |
Output is correct |
43 |
Correct |
9 ms |
22256 KB |
Output is correct |
44 |
Correct |
31 ms |
22712 KB |
Output is correct |
45 |
Correct |
36 ms |
23984 KB |
Output is correct |
46 |
Correct |
43 ms |
25980 KB |
Output is correct |
47 |
Correct |
14 ms |
25980 KB |
Output is correct |
48 |
Correct |
3 ms |
25980 KB |
Output is correct |
49 |
Correct |
102 ms |
28384 KB |
Output is correct |
50 |
Correct |
48 ms |
30792 KB |
Output is correct |
51 |
Correct |
68 ms |
32668 KB |
Output is correct |
52 |
Correct |
50 ms |
34944 KB |
Output is correct |
53 |
Correct |
47 ms |
37372 KB |
Output is correct |
54 |
Correct |
111 ms |
39468 KB |
Output is correct |
55 |
Correct |
47 ms |
41452 KB |
Output is correct |
56 |
Correct |
58 ms |
43760 KB |
Output is correct |
57 |
Correct |
43 ms |
45592 KB |
Output is correct |
58 |
Correct |
461 ms |
47968 KB |
Output is correct |
59 |
Correct |
477 ms |
50316 KB |
Output is correct |
60 |
Correct |
445 ms |
52228 KB |
Output is correct |
61 |
Correct |
474 ms |
54764 KB |
Output is correct |
62 |
Correct |
450 ms |
56820 KB |
Output is correct |
63 |
Correct |
492 ms |
59328 KB |
Output is correct |
64 |
Correct |
436 ms |
61324 KB |
Output is correct |
65 |
Correct |
1 ms |
61324 KB |
Output is correct |
66 |
Correct |
1 ms |
61324 KB |
Output is correct |
67 |
Correct |
522 ms |
63560 KB |
Output is correct |
68 |
Correct |
512 ms |
65760 KB |
Output is correct |
69 |
Correct |
442 ms |
67472 KB |
Output is correct |
70 |
Correct |
476 ms |
69828 KB |
Output is correct |
71 |
Correct |
481 ms |
71884 KB |
Output is correct |
72 |
Correct |
464 ms |
74152 KB |
Output is correct |
73 |
Correct |
456 ms |
76000 KB |
Output is correct |
74 |
Correct |
516 ms |
78304 KB |
Output is correct |
75 |
Correct |
493 ms |
80532 KB |
Output is correct |
76 |
Correct |
500 ms |
82856 KB |
Output is correct |
77 |
Correct |
129 ms |
85296 KB |
Output is correct |
78 |
Correct |
49 ms |
87188 KB |
Output is correct |
79 |
Correct |
79 ms |
89120 KB |
Output is correct |
80 |
Correct |
79 ms |
91496 KB |
Output is correct |
81 |
Correct |
72 ms |
93204 KB |
Output is correct |
82 |
Correct |
72 ms |
95756 KB |
Output is correct |
83 |
Correct |
53 ms |
97584 KB |
Output is correct |
84 |
Correct |
332 ms |
100048 KB |
Output is correct |
85 |
Correct |
551 ms |
102396 KB |
Output is correct |
86 |
Correct |
2 ms |
102396 KB |
Output is correct |
87 |
Correct |
2 ms |
102396 KB |
Output is correct |
88 |
Correct |
535 ms |
104812 KB |
Output is correct |
89 |
Correct |
104 ms |
104812 KB |
Output is correct |
90 |
Correct |
2 ms |
104812 KB |
Output is correct |