//Challenge: Accepted
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#define ll long long
#define maxn 100005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
struct rect{
int x1, y1, x2, y2;
rect() {
x1 = 0, y1 = 0, x2 = 0, y2 = 0;
}
rect(int a, int b, int c, int d) {
x1 = a, y1 = b, x2 = c, y2 = d;
}
};
vector<rect> v;
ll solve(ll n, ll len) {
ll val = 0, block = n / len;
for (int i = 0;i < block;i++) {
val += len * len * (block / 2 + (block % 2 && i % 2 ? 1 : 0));
}
for (rect a:v) {
val += (a.x1 / len + a.y1 / len) % 2 ? -1 : 1;
}
val = min(val, n * n - val);
//cout << len << " " << val << endl;
return val;
}
int main() {
io
ll n, k;
cin >> n >> k;
for (int i = 0;i < k;i++) {
ll x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
x1--, y1--, x2--, y2--;
v.push_back(rect(x1, y1, x2, y2));
}
ll ans = 1LL<<60;
for (ll i = 1;i * i <= n;i++) {
if (n % i == 0) {
ans = min(ans, solve(n, i));
if (i * i != n && i != 1) {
ans = min(ans, solve(n, n / i));
}
}
}
cout << ans << endl;
}
/*
2 0
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
*/
# |
결과 |
실행 시간 |
메모리 |
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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
1800 KB |
Output is correct |
2 |
Correct |
7 ms |
1008 KB |
Output is correct |
3 |
Correct |
16 ms |
1516 KB |
Output is correct |
4 |
Correct |
18 ms |
1516 KB |
Output is correct |
5 |
Correct |
22 ms |
1516 KB |
Output is correct |
6 |
Correct |
14 ms |
1664 KB |
Output is correct |
7 |
Correct |
4 ms |
620 KB |
Output is correct |
8 |
Correct |
16 ms |
1516 KB |
Output is correct |
9 |
Correct |
37 ms |
2536 KB |
Output is correct |
10 |
Correct |
20 ms |
1672 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 |
492 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 |
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 |
492 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 |
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 |
10 ms |
1008 KB |
Output is correct |
17 |
Correct |
29 ms |
2536 KB |
Output is correct |
18 |
Correct |
37 ms |
2536 KB |
Output is correct |
19 |
Correct |
57 ms |
2536 KB |
Output is correct |
20 |
Correct |
64 ms |
2536 KB |
Output is correct |
21 |
Correct |
28 ms |
2536 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
18 ms |
1516 KB |
Output is correct |
24 |
Correct |
33 ms |
2536 KB |
Output is correct |
25 |
Correct |
4 ms |
748 KB |
Output is correct |
26 |
Correct |
21 ms |
1516 KB |
Output is correct |
27 |
Correct |
27 ms |
2536 KB |
Output is correct |
28 |
Correct |
38 ms |
2536 KB |
Output is correct |
29 |
Correct |
12 ms |
1516 KB |
Output is correct |
30 |
Correct |
2 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
1800 KB |
Output is correct |
2 |
Correct |
7 ms |
1008 KB |
Output is correct |
3 |
Correct |
16 ms |
1516 KB |
Output is correct |
4 |
Correct |
18 ms |
1516 KB |
Output is correct |
5 |
Correct |
22 ms |
1516 KB |
Output is correct |
6 |
Correct |
14 ms |
1664 KB |
Output is correct |
7 |
Correct |
4 ms |
620 KB |
Output is correct |
8 |
Correct |
16 ms |
1516 KB |
Output is correct |
9 |
Correct |
37 ms |
2536 KB |
Output is correct |
10 |
Correct |
20 ms |
1672 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 |
492 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 |
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 |
10 ms |
1008 KB |
Output is correct |
27 |
Correct |
29 ms |
2536 KB |
Output is correct |
28 |
Correct |
37 ms |
2536 KB |
Output is correct |
29 |
Correct |
57 ms |
2536 KB |
Output is correct |
30 |
Correct |
64 ms |
2536 KB |
Output is correct |
31 |
Correct |
28 ms |
2536 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
18 ms |
1516 KB |
Output is correct |
34 |
Correct |
33 ms |
2536 KB |
Output is correct |
35 |
Correct |
4 ms |
748 KB |
Output is correct |
36 |
Correct |
21 ms |
1516 KB |
Output is correct |
37 |
Correct |
27 ms |
2536 KB |
Output is correct |
38 |
Correct |
38 ms |
2536 KB |
Output is correct |
39 |
Correct |
12 ms |
1516 KB |
Output is correct |
40 |
Correct |
2 ms |
492 KB |
Output is correct |
41 |
Correct |
57 ms |
2536 KB |
Output is correct |
42 |
Correct |
39 ms |
2536 KB |
Output is correct |
43 |
Correct |
44 ms |
2536 KB |
Output is correct |
44 |
Correct |
39 ms |
2536 KB |
Output is correct |
45 |
Correct |
39 ms |
2536 KB |
Output is correct |
46 |
Correct |
63 ms |
2536 KB |
Output is correct |
47 |
Correct |
35 ms |
2536 KB |
Output is correct |
48 |
Correct |
42 ms |
2536 KB |
Output is correct |
49 |
Correct |
38 ms |
2536 KB |
Output is correct |
50 |
Correct |
183 ms |
2536 KB |
Output is correct |
51 |
Correct |
195 ms |
2536 KB |
Output is correct |
52 |
Correct |
182 ms |
2536 KB |
Output is correct |
53 |
Correct |
194 ms |
2536 KB |
Output is correct |
54 |
Correct |
182 ms |
2536 KB |
Output is correct |
55 |
Correct |
204 ms |
2664 KB |
Output is correct |
56 |
Correct |
173 ms |
2536 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 |
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 |
26 ms |
1800 KB |
Output is correct |
10 |
Correct |
7 ms |
1008 KB |
Output is correct |
11 |
Correct |
16 ms |
1516 KB |
Output is correct |
12 |
Correct |
18 ms |
1516 KB |
Output is correct |
13 |
Correct |
22 ms |
1516 KB |
Output is correct |
14 |
Correct |
14 ms |
1664 KB |
Output is correct |
15 |
Correct |
4 ms |
620 KB |
Output is correct |
16 |
Correct |
16 ms |
1516 KB |
Output is correct |
17 |
Correct |
37 ms |
2536 KB |
Output is correct |
18 |
Correct |
20 ms |
1672 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 |
492 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 |
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 |
10 ms |
1008 KB |
Output is correct |
35 |
Correct |
29 ms |
2536 KB |
Output is correct |
36 |
Correct |
37 ms |
2536 KB |
Output is correct |
37 |
Correct |
57 ms |
2536 KB |
Output is correct |
38 |
Correct |
64 ms |
2536 KB |
Output is correct |
39 |
Correct |
28 ms |
2536 KB |
Output is correct |
40 |
Correct |
1 ms |
364 KB |
Output is correct |
41 |
Correct |
18 ms |
1516 KB |
Output is correct |
42 |
Correct |
33 ms |
2536 KB |
Output is correct |
43 |
Correct |
4 ms |
748 KB |
Output is correct |
44 |
Correct |
21 ms |
1516 KB |
Output is correct |
45 |
Correct |
27 ms |
2536 KB |
Output is correct |
46 |
Correct |
38 ms |
2536 KB |
Output is correct |
47 |
Correct |
12 ms |
1516 KB |
Output is correct |
48 |
Correct |
2 ms |
492 KB |
Output is correct |
49 |
Correct |
57 ms |
2536 KB |
Output is correct |
50 |
Correct |
39 ms |
2536 KB |
Output is correct |
51 |
Correct |
44 ms |
2536 KB |
Output is correct |
52 |
Correct |
39 ms |
2536 KB |
Output is correct |
53 |
Correct |
39 ms |
2536 KB |
Output is correct |
54 |
Correct |
63 ms |
2536 KB |
Output is correct |
55 |
Correct |
35 ms |
2536 KB |
Output is correct |
56 |
Correct |
42 ms |
2536 KB |
Output is correct |
57 |
Correct |
38 ms |
2536 KB |
Output is correct |
58 |
Correct |
183 ms |
2536 KB |
Output is correct |
59 |
Correct |
195 ms |
2536 KB |
Output is correct |
60 |
Correct |
182 ms |
2536 KB |
Output is correct |
61 |
Correct |
194 ms |
2536 KB |
Output is correct |
62 |
Correct |
182 ms |
2536 KB |
Output is correct |
63 |
Correct |
204 ms |
2664 KB |
Output is correct |
64 |
Correct |
173 ms |
2536 KB |
Output is correct |
65 |
Correct |
0 ms |
364 KB |
Output is correct |
66 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
67 |
Halted |
0 ms |
0 KB |
- |