#include <bits/stdc++.h>
#define int long long
using namespace std;
#define file ""
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define getbit(x, i) (((x) >> (i)) & 1)
#define bit(x) (1LL << (x))
#define popcount __builtin_popcountll
mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r) {
return l + rd() % (r - l + 1);
}
const int N = 1e6 + 5;
const int mod = (int)1e9 + 7; // 998244353;
const int lg = 25; // lg + 1
const int oo = 1e9;
const long long ooo = 1e18;
template<class X, class Y> bool mini(X &a, Y b) {
return a > b ? (a = b, true) : false;
}
template<class X, class Y> bool maxi(X &a, Y b) {
return a < b ? (a = b, true) : false;
}
void add(int &a, int b) {
a += b;
if (a >= mod) a -= mod;
if (a < 0) a += mod;
}
struct rec {
int x, y, u, v;
rec (int _x = 0, int _y = 0, int _u = 0, int _v = 0) {
x = _x;
y = _y;
u = _u;
v = _v;
}
};
int n, k;
vector<rec> subrec;
int area = 0;
int res = ooo;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
// freopen(file".inp", "r", stdin);
// freopen(file".out", "w", stdout);
cin >> n >> k;
for (int i = 1; i <= k; ++i) {
int x, y, u, v;
cin >> x >> y >> u >> v;
--x, --y, --u, --v;
subrec.push_back(rec(x, y, u, v));
area += (u - x + 1) * (v - y + 1);
}
for (int i = 1; i < n; ++i) if (n % i == 0) {
int d = n / i;
int a = (d * d + 1) / 2 * i * i;
int b = (d * d) / 2 * i * i;
int cnt = 0;
for (auto [x, y, u, v] : subrec) {
if ((x / i) % 2 == (y / i) % 2) ++cnt;
}
res = min(res, (a - cnt) + (area - cnt));
res = min(res, (b - (area - cnt)) + cnt);
}
cout << res;
return 0;
}
/*
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
4052 KB |
Output is correct |
2 |
Correct |
6 ms |
1804 KB |
Output is correct |
3 |
Correct |
17 ms |
3416 KB |
Output is correct |
4 |
Correct |
12 ms |
3288 KB |
Output is correct |
5 |
Correct |
15 ms |
3616 KB |
Output is correct |
6 |
Correct |
12 ms |
3284 KB |
Output is correct |
7 |
Correct |
3 ms |
988 KB |
Output is correct |
8 |
Correct |
15 ms |
3288 KB |
Output is correct |
9 |
Correct |
40 ms |
6348 KB |
Output is correct |
10 |
Correct |
16 ms |
3544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
7 ms |
2012 KB |
Output is correct |
17 |
Correct |
21 ms |
6868 KB |
Output is correct |
18 |
Correct |
38 ms |
7168 KB |
Output is correct |
19 |
Correct |
42 ms |
5840 KB |
Output is correct |
20 |
Correct |
47 ms |
7688 KB |
Output is correct |
21 |
Correct |
18 ms |
6096 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
19 ms |
3284 KB |
Output is correct |
24 |
Correct |
24 ms |
6332 KB |
Output is correct |
25 |
Correct |
4 ms |
1244 KB |
Output is correct |
26 |
Correct |
21 ms |
3288 KB |
Output is correct |
27 |
Correct |
28 ms |
5836 KB |
Output is correct |
28 |
Correct |
24 ms |
7120 KB |
Output is correct |
29 |
Correct |
13 ms |
3024 KB |
Output is correct |
30 |
Correct |
2 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
4052 KB |
Output is correct |
2 |
Correct |
6 ms |
1804 KB |
Output is correct |
3 |
Correct |
17 ms |
3416 KB |
Output is correct |
4 |
Correct |
12 ms |
3288 KB |
Output is correct |
5 |
Correct |
15 ms |
3616 KB |
Output is correct |
6 |
Correct |
12 ms |
3284 KB |
Output is correct |
7 |
Correct |
3 ms |
988 KB |
Output is correct |
8 |
Correct |
15 ms |
3288 KB |
Output is correct |
9 |
Correct |
40 ms |
6348 KB |
Output is correct |
10 |
Correct |
16 ms |
3544 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
7 ms |
2012 KB |
Output is correct |
27 |
Correct |
21 ms |
6868 KB |
Output is correct |
28 |
Correct |
38 ms |
7168 KB |
Output is correct |
29 |
Correct |
42 ms |
5840 KB |
Output is correct |
30 |
Correct |
47 ms |
7688 KB |
Output is correct |
31 |
Correct |
18 ms |
6096 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
19 ms |
3284 KB |
Output is correct |
34 |
Correct |
24 ms |
6332 KB |
Output is correct |
35 |
Correct |
4 ms |
1244 KB |
Output is correct |
36 |
Correct |
21 ms |
3288 KB |
Output is correct |
37 |
Correct |
28 ms |
5836 KB |
Output is correct |
38 |
Correct |
24 ms |
7120 KB |
Output is correct |
39 |
Correct |
13 ms |
3024 KB |
Output is correct |
40 |
Correct |
2 ms |
600 KB |
Output is correct |
41 |
Correct |
61 ms |
7456 KB |
Output is correct |
42 |
Correct |
37 ms |
7628 KB |
Output is correct |
43 |
Correct |
38 ms |
6396 KB |
Output is correct |
44 |
Correct |
26 ms |
6408 KB |
Output is correct |
45 |
Correct |
28 ms |
8200 KB |
Output is correct |
46 |
Correct |
62 ms |
6356 KB |
Output is correct |
47 |
Correct |
33 ms |
7888 KB |
Output is correct |
48 |
Correct |
29 ms |
8392 KB |
Output is correct |
49 |
Correct |
24 ms |
7156 KB |
Output is correct |
50 |
Correct |
145 ms |
6860 KB |
Output is correct |
51 |
Correct |
157 ms |
7380 KB |
Output is correct |
52 |
Correct |
158 ms |
7400 KB |
Output is correct |
53 |
Correct |
155 ms |
7636 KB |
Output is correct |
54 |
Correct |
144 ms |
7636 KB |
Output is correct |
55 |
Correct |
175 ms |
6952 KB |
Output is correct |
56 |
Correct |
140 ms |
8400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
17 ms |
4052 KB |
Output is correct |
10 |
Correct |
6 ms |
1804 KB |
Output is correct |
11 |
Correct |
17 ms |
3416 KB |
Output is correct |
12 |
Correct |
12 ms |
3288 KB |
Output is correct |
13 |
Correct |
15 ms |
3616 KB |
Output is correct |
14 |
Correct |
12 ms |
3284 KB |
Output is correct |
15 |
Correct |
3 ms |
988 KB |
Output is correct |
16 |
Correct |
15 ms |
3288 KB |
Output is correct |
17 |
Correct |
40 ms |
6348 KB |
Output is correct |
18 |
Correct |
16 ms |
3544 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
600 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
7 ms |
2012 KB |
Output is correct |
35 |
Correct |
21 ms |
6868 KB |
Output is correct |
36 |
Correct |
38 ms |
7168 KB |
Output is correct |
37 |
Correct |
42 ms |
5840 KB |
Output is correct |
38 |
Correct |
47 ms |
7688 KB |
Output is correct |
39 |
Correct |
18 ms |
6096 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
19 ms |
3284 KB |
Output is correct |
42 |
Correct |
24 ms |
6332 KB |
Output is correct |
43 |
Correct |
4 ms |
1244 KB |
Output is correct |
44 |
Correct |
21 ms |
3288 KB |
Output is correct |
45 |
Correct |
28 ms |
5836 KB |
Output is correct |
46 |
Correct |
24 ms |
7120 KB |
Output is correct |
47 |
Correct |
13 ms |
3024 KB |
Output is correct |
48 |
Correct |
2 ms |
600 KB |
Output is correct |
49 |
Correct |
61 ms |
7456 KB |
Output is correct |
50 |
Correct |
37 ms |
7628 KB |
Output is correct |
51 |
Correct |
38 ms |
6396 KB |
Output is correct |
52 |
Correct |
26 ms |
6408 KB |
Output is correct |
53 |
Correct |
28 ms |
8200 KB |
Output is correct |
54 |
Correct |
62 ms |
6356 KB |
Output is correct |
55 |
Correct |
33 ms |
7888 KB |
Output is correct |
56 |
Correct |
29 ms |
8392 KB |
Output is correct |
57 |
Correct |
24 ms |
7156 KB |
Output is correct |
58 |
Correct |
145 ms |
6860 KB |
Output is correct |
59 |
Correct |
157 ms |
7380 KB |
Output is correct |
60 |
Correct |
158 ms |
7400 KB |
Output is correct |
61 |
Correct |
155 ms |
7636 KB |
Output is correct |
62 |
Correct |
144 ms |
7636 KB |
Output is correct |
63 |
Correct |
175 ms |
6952 KB |
Output is correct |
64 |
Correct |
140 ms |
8400 KB |
Output is correct |
65 |
Correct |
0 ms |
348 KB |
Output is correct |
66 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
67 |
Halted |
0 ms |
0 KB |
- |