#include <iostream>
#include <climits>
#include <tuple>
#include <vector>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define MN 107171
using namespace std;
using ll = long long;
ll n, k;
tuple<int, int, int, int> R[MN];
static inline ll calc(ll a, ll b, ll l) {
if(a % l == 0 && b % l == 0)
return ((a / l) * (b / l) + 1) / 2 * l * l;
if(a % l) {
ll nrseg;
if(a / l % 2ll == 0) {
if(b % (2ll * l) <= l) nrseg = (b / (2ll * l)) * l + b % (2 * l);
else nrseg = (b / (2ll * l) + 1) * l;
} else {
if(b % (2ll * l) <= l) nrseg = (b / (2ll * l)) * l;
else nrseg = (b / (2ll * l) - 1) * l + b % (2 * l);
}
return calc(a - (a % l), b, l) + (a % l) * nrseg;
}
return calc(b, a, l);
}
ll sol(ll l) {
ll arie = ((n / l) * (n / l) + 1) / 2 * l * l, selec;
for(int i = 1; i <= k; ++i) {
auto &[a, b, c, d] = R[i];
selec = calc(c, d, l) + calc(a-1, b-1, l) - calc(c, b-1, l) - calc(a-1, d, l);
arie += (c - a + 1) * (d - b + 1) - 2 * selec;
}
return min(arie, 1ll * n * n - arie);
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cin >> n >> k;
for(int i = 1, a, b, c, d; i <= k; ++i)
cin >> a >> b >> c >> d, R[i] = make_tuple(a, b, c, d);
ll re = LLONG_MAX;
for(int i = 1; i < n; ++i)
if(n % i == 0) re = min(re, sol(i));
cout << re << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
1292 KB |
Output is correct |
2 |
Correct |
5 ms |
460 KB |
Output is correct |
3 |
Correct |
15 ms |
860 KB |
Output is correct |
4 |
Correct |
14 ms |
924 KB |
Output is correct |
5 |
Correct |
18 ms |
1172 KB |
Output is correct |
6 |
Correct |
12 ms |
868 KB |
Output is correct |
7 |
Correct |
3 ms |
332 KB |
Output is correct |
8 |
Correct |
13 ms |
844 KB |
Output is correct |
9 |
Correct |
33 ms |
1720 KB |
Output is correct |
10 |
Correct |
17 ms |
1004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
19 ms |
748 KB |
Output is correct |
17 |
Correct |
23 ms |
1544 KB |
Output is correct |
18 |
Correct |
57 ms |
1740 KB |
Output is correct |
19 |
Correct |
387 ms |
1692 KB |
Output is correct |
20 |
Correct |
449 ms |
1756 KB |
Output is correct |
21 |
Correct |
25 ms |
1556 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
53 ms |
972 KB |
Output is correct |
24 |
Correct |
54 ms |
1696 KB |
Output is correct |
25 |
Correct |
11 ms |
452 KB |
Output is correct |
26 |
Correct |
34 ms |
1100 KB |
Output is correct |
27 |
Correct |
60 ms |
1356 KB |
Output is correct |
28 |
Correct |
56 ms |
1796 KB |
Output is correct |
29 |
Correct |
9 ms |
744 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
1292 KB |
Output is correct |
2 |
Correct |
5 ms |
460 KB |
Output is correct |
3 |
Correct |
15 ms |
860 KB |
Output is correct |
4 |
Correct |
14 ms |
924 KB |
Output is correct |
5 |
Correct |
18 ms |
1172 KB |
Output is correct |
6 |
Correct |
12 ms |
868 KB |
Output is correct |
7 |
Correct |
3 ms |
332 KB |
Output is correct |
8 |
Correct |
13 ms |
844 KB |
Output is correct |
9 |
Correct |
33 ms |
1720 KB |
Output is correct |
10 |
Correct |
17 ms |
1004 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
19 ms |
748 KB |
Output is correct |
27 |
Correct |
23 ms |
1544 KB |
Output is correct |
28 |
Correct |
57 ms |
1740 KB |
Output is correct |
29 |
Correct |
387 ms |
1692 KB |
Output is correct |
30 |
Correct |
449 ms |
1756 KB |
Output is correct |
31 |
Correct |
25 ms |
1556 KB |
Output is correct |
32 |
Correct |
2 ms |
332 KB |
Output is correct |
33 |
Correct |
53 ms |
972 KB |
Output is correct |
34 |
Correct |
54 ms |
1696 KB |
Output is correct |
35 |
Correct |
11 ms |
452 KB |
Output is correct |
36 |
Correct |
34 ms |
1100 KB |
Output is correct |
37 |
Correct |
60 ms |
1356 KB |
Output is correct |
38 |
Correct |
56 ms |
1796 KB |
Output is correct |
39 |
Correct |
9 ms |
744 KB |
Output is correct |
40 |
Correct |
2 ms |
332 KB |
Output is correct |
41 |
Correct |
363 ms |
1592 KB |
Output is correct |
42 |
Correct |
68 ms |
1768 KB |
Output is correct |
43 |
Correct |
172 ms |
1600 KB |
Output is correct |
44 |
Correct |
63 ms |
1720 KB |
Output is correct |
45 |
Correct |
45 ms |
1724 KB |
Output is correct |
46 |
Correct |
391 ms |
1748 KB |
Output is correct |
47 |
Correct |
29 ms |
1604 KB |
Output is correct |
48 |
Correct |
127 ms |
1660 KB |
Output is correct |
49 |
Correct |
60 ms |
1604 KB |
Output is correct |
50 |
Execution timed out |
2061 ms |
1708 KB |
Time limit exceeded |
51 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
23 ms |
1292 KB |
Output is correct |
10 |
Correct |
5 ms |
460 KB |
Output is correct |
11 |
Correct |
15 ms |
860 KB |
Output is correct |
12 |
Correct |
14 ms |
924 KB |
Output is correct |
13 |
Correct |
18 ms |
1172 KB |
Output is correct |
14 |
Correct |
12 ms |
868 KB |
Output is correct |
15 |
Correct |
3 ms |
332 KB |
Output is correct |
16 |
Correct |
13 ms |
844 KB |
Output is correct |
17 |
Correct |
33 ms |
1720 KB |
Output is correct |
18 |
Correct |
17 ms |
1004 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
0 ms |
204 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
2 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
19 ms |
748 KB |
Output is correct |
35 |
Correct |
23 ms |
1544 KB |
Output is correct |
36 |
Correct |
57 ms |
1740 KB |
Output is correct |
37 |
Correct |
387 ms |
1692 KB |
Output is correct |
38 |
Correct |
449 ms |
1756 KB |
Output is correct |
39 |
Correct |
25 ms |
1556 KB |
Output is correct |
40 |
Correct |
2 ms |
332 KB |
Output is correct |
41 |
Correct |
53 ms |
972 KB |
Output is correct |
42 |
Correct |
54 ms |
1696 KB |
Output is correct |
43 |
Correct |
11 ms |
452 KB |
Output is correct |
44 |
Correct |
34 ms |
1100 KB |
Output is correct |
45 |
Correct |
60 ms |
1356 KB |
Output is correct |
46 |
Correct |
56 ms |
1796 KB |
Output is correct |
47 |
Correct |
9 ms |
744 KB |
Output is correct |
48 |
Correct |
2 ms |
332 KB |
Output is correct |
49 |
Correct |
363 ms |
1592 KB |
Output is correct |
50 |
Correct |
68 ms |
1768 KB |
Output is correct |
51 |
Correct |
172 ms |
1600 KB |
Output is correct |
52 |
Correct |
63 ms |
1720 KB |
Output is correct |
53 |
Correct |
45 ms |
1724 KB |
Output is correct |
54 |
Correct |
391 ms |
1748 KB |
Output is correct |
55 |
Correct |
29 ms |
1604 KB |
Output is correct |
56 |
Correct |
127 ms |
1660 KB |
Output is correct |
57 |
Correct |
60 ms |
1604 KB |
Output is correct |
58 |
Execution timed out |
2061 ms |
1708 KB |
Time limit exceeded |
59 |
Halted |
0 ms |
0 KB |
- |