#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = (int)1e5 + 5;
const ll INF = (ll)1e18;
ll x[3][MAXN];
ll y[3][MAXN];
ll n, k;
ll dup(ll a, ll b) {
return (a + b - 1ll) / b;
}
ll S(ll x) {
return x * x;
}
ll sz_of_corner(ll n, ll len) {
return (S(dup(n / len, 2)) + S((n / len) / 2ll)) * (len * len);
}
ll solve(ll len) {
if (n == len) {
return INF;
}
ll bad_white[2] = {0, 0};
ll good_black[2] = {0, 0};
for (int i = 1; i <= k; i++) {
assert(x[1][i] == x[2][i] && y[1][i] == y[2][i]);
int xx = dup(x[1][i], len);
int yy = dup(y[1][i], len);
// в правом левом углу черный цвет
if ((xx + yy) % 2 == 0) { // черный цвет
good_black[1]++;
} else { // белый
bad_white[1]++;
}
// в правом левом углу белый цвет
if ((xx + yy) % 2 == 0) { // белый цвет
bad_white[0]++;
} else { // черный
good_black[0]++;
}
}
return min(bad_white[1] + sz_of_corner(n, len) - good_black[1],
bad_white[0] + ((S(n) - sz_of_corner(n, len)) - good_black[0]));
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> k;
for (int i = 1; i <= k; i++) {
cin >> x[1][i] >> y[1][i] >> x[2][i] >> y[2][i];
}
ll ans = INF;
for (int i = 1; i * i <= n; i++) {
if (n % i == 0) {
ans = min(ans, solve(i));
ans = min(ans, solve(n / i));
}
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
3820 KB |
Output is correct |
2 |
Correct |
7 ms |
1260 KB |
Output is correct |
3 |
Correct |
16 ms |
2540 KB |
Output is correct |
4 |
Correct |
18 ms |
2668 KB |
Output is correct |
5 |
Correct |
23 ms |
3436 KB |
Output is correct |
6 |
Correct |
14 ms |
2284 KB |
Output is correct |
7 |
Correct |
4 ms |
748 KB |
Output is correct |
8 |
Correct |
14 ms |
2284 KB |
Output is correct |
9 |
Correct |
38 ms |
5228 KB |
Output is correct |
10 |
Correct |
21 ms |
3180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
384 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 |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
384 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 |
364 KB |
Output is correct |
16 |
Correct |
11 ms |
1644 KB |
Output is correct |
17 |
Correct |
30 ms |
4460 KB |
Output is correct |
18 |
Correct |
37 ms |
5100 KB |
Output is correct |
19 |
Correct |
68 ms |
4588 KB |
Output is correct |
20 |
Correct |
77 ms |
5100 KB |
Output is correct |
21 |
Correct |
29 ms |
4204 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
19 ms |
2412 KB |
Output is correct |
24 |
Correct |
34 ms |
4588 KB |
Output is correct |
25 |
Correct |
4 ms |
748 KB |
Output is correct |
26 |
Correct |
22 ms |
3100 KB |
Output is correct |
27 |
Correct |
28 ms |
3660 KB |
Output is correct |
28 |
Correct |
35 ms |
4844 KB |
Output is correct |
29 |
Correct |
12 ms |
1900 KB |
Output is correct |
30 |
Correct |
2 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
3820 KB |
Output is correct |
2 |
Correct |
7 ms |
1260 KB |
Output is correct |
3 |
Correct |
16 ms |
2540 KB |
Output is correct |
4 |
Correct |
18 ms |
2668 KB |
Output is correct |
5 |
Correct |
23 ms |
3436 KB |
Output is correct |
6 |
Correct |
14 ms |
2284 KB |
Output is correct |
7 |
Correct |
4 ms |
748 KB |
Output is correct |
8 |
Correct |
14 ms |
2284 KB |
Output is correct |
9 |
Correct |
38 ms |
5228 KB |
Output is correct |
10 |
Correct |
21 ms |
3180 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 |
364 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 |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 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 |
11 ms |
1644 KB |
Output is correct |
27 |
Correct |
30 ms |
4460 KB |
Output is correct |
28 |
Correct |
37 ms |
5100 KB |
Output is correct |
29 |
Correct |
68 ms |
4588 KB |
Output is correct |
30 |
Correct |
77 ms |
5100 KB |
Output is correct |
31 |
Correct |
29 ms |
4204 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
19 ms |
2412 KB |
Output is correct |
34 |
Correct |
34 ms |
4588 KB |
Output is correct |
35 |
Correct |
4 ms |
748 KB |
Output is correct |
36 |
Correct |
22 ms |
3100 KB |
Output is correct |
37 |
Correct |
28 ms |
3660 KB |
Output is correct |
38 |
Correct |
35 ms |
4844 KB |
Output is correct |
39 |
Correct |
12 ms |
1900 KB |
Output is correct |
40 |
Correct |
2 ms |
492 KB |
Output is correct |
41 |
Correct |
66 ms |
4972 KB |
Output is correct |
42 |
Correct |
40 ms |
5612 KB |
Output is correct |
43 |
Correct |
49 ms |
4992 KB |
Output is correct |
44 |
Correct |
39 ms |
5356 KB |
Output is correct |
45 |
Correct |
39 ms |
5740 KB |
Output is correct |
46 |
Correct |
75 ms |
5484 KB |
Output is correct |
47 |
Correct |
34 ms |
5100 KB |
Output is correct |
48 |
Correct |
45 ms |
5228 KB |
Output is correct |
49 |
Correct |
36 ms |
4972 KB |
Output is correct |
50 |
Correct |
242 ms |
5484 KB |
Output is correct |
51 |
Correct |
257 ms |
5868 KB |
Output is correct |
52 |
Correct |
241 ms |
5484 KB |
Output is correct |
53 |
Correct |
255 ms |
5740 KB |
Output is correct |
54 |
Correct |
234 ms |
5228 KB |
Output is correct |
55 |
Correct |
269 ms |
5868 KB |
Output is correct |
56 |
Correct |
232 ms |
5100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
26 ms |
3820 KB |
Output is correct |
10 |
Correct |
7 ms |
1260 KB |
Output is correct |
11 |
Correct |
16 ms |
2540 KB |
Output is correct |
12 |
Correct |
18 ms |
2668 KB |
Output is correct |
13 |
Correct |
23 ms |
3436 KB |
Output is correct |
14 |
Correct |
14 ms |
2284 KB |
Output is correct |
15 |
Correct |
4 ms |
748 KB |
Output is correct |
16 |
Correct |
14 ms |
2284 KB |
Output is correct |
17 |
Correct |
38 ms |
5228 KB |
Output is correct |
18 |
Correct |
21 ms |
3180 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 |
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 |
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 |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 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 |
11 ms |
1644 KB |
Output is correct |
35 |
Correct |
30 ms |
4460 KB |
Output is correct |
36 |
Correct |
37 ms |
5100 KB |
Output is correct |
37 |
Correct |
68 ms |
4588 KB |
Output is correct |
38 |
Correct |
77 ms |
5100 KB |
Output is correct |
39 |
Correct |
29 ms |
4204 KB |
Output is correct |
40 |
Correct |
1 ms |
364 KB |
Output is correct |
41 |
Correct |
19 ms |
2412 KB |
Output is correct |
42 |
Correct |
34 ms |
4588 KB |
Output is correct |
43 |
Correct |
4 ms |
748 KB |
Output is correct |
44 |
Correct |
22 ms |
3100 KB |
Output is correct |
45 |
Correct |
28 ms |
3660 KB |
Output is correct |
46 |
Correct |
35 ms |
4844 KB |
Output is correct |
47 |
Correct |
12 ms |
1900 KB |
Output is correct |
48 |
Correct |
2 ms |
492 KB |
Output is correct |
49 |
Correct |
66 ms |
4972 KB |
Output is correct |
50 |
Correct |
40 ms |
5612 KB |
Output is correct |
51 |
Correct |
49 ms |
4992 KB |
Output is correct |
52 |
Correct |
39 ms |
5356 KB |
Output is correct |
53 |
Correct |
39 ms |
5740 KB |
Output is correct |
54 |
Correct |
75 ms |
5484 KB |
Output is correct |
55 |
Correct |
34 ms |
5100 KB |
Output is correct |
56 |
Correct |
45 ms |
5228 KB |
Output is correct |
57 |
Correct |
36 ms |
4972 KB |
Output is correct |
58 |
Correct |
242 ms |
5484 KB |
Output is correct |
59 |
Correct |
257 ms |
5868 KB |
Output is correct |
60 |
Correct |
241 ms |
5484 KB |
Output is correct |
61 |
Correct |
255 ms |
5740 KB |
Output is correct |
62 |
Correct |
234 ms |
5228 KB |
Output is correct |
63 |
Correct |
269 ms |
5868 KB |
Output is correct |
64 |
Correct |
232 ms |
5100 KB |
Output is correct |
65 |
Correct |
1 ms |
364 KB |
Output is correct |
66 |
Runtime error |
2 ms |
620 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
67 |
Halted |
0 ms |
0 KB |
- |