#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<ll,ll>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
/*
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
*/
int main(){
// freopen("school.in", "r", stdin);
// freopen("school.out", "w", stdout);
int n, k;
cin >> n >> k;
int x1[k + 1], x2[k + 1], y1[k + 1], y2[k + 1];
for(int i = 1; i <= k; ++i){
cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
x1[i]--;
y1[i]--;
x2[i]--;
y2[i]--;
}
ll ans = 1e18 + 1;
for(ll a = 1; a <n; a++){
if(n % a) continue;
ll v = n / a;
ll cnt = 0;
if(v % 2 == 1)
cnt += v * (v / 2) + (v + 1) / 2;
else cnt = v * v / 2;
cnt *= a * a;
for(int i = 1; i <= k; i++){
int X = x1[i] / a, Y = y1[i] / a;
if((X + Y) & 1)
cnt++;
else cnt--;
}
ans = min(ans, cnt);
}
for(ll a = 1; a <n; a++){
if(n % a) continue;
ll v = n / a;
ll cnt = -1;
if(v % 2 == 1)
cnt += v * (v / 2) + (v + 1) / 2;
else cnt = v * v / 2;
cnt *= a * a;
for(int i = 1; i <= k; i++){
int X = x1[i] / a, Y = y1[i] / a;
if((X + Y) & 1)
cnt--;
else cnt++;
}
ans = min(ans, cnt);
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
1236 KB |
Output is correct |
2 |
Correct |
17 ms |
532 KB |
Output is correct |
3 |
Correct |
42 ms |
852 KB |
Output is correct |
4 |
Correct |
43 ms |
980 KB |
Output is correct |
5 |
Correct |
59 ms |
1124 KB |
Output is correct |
6 |
Correct |
43 ms |
816 KB |
Output is correct |
7 |
Correct |
8 ms |
340 KB |
Output is correct |
8 |
Correct |
39 ms |
828 KB |
Output is correct |
9 |
Correct |
89 ms |
1688 KB |
Output is correct |
10 |
Correct |
53 ms |
1060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
2 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
2 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
28 ms |
720 KB |
Output is correct |
17 |
Correct |
67 ms |
1588 KB |
Output is correct |
18 |
Correct |
84 ms |
1816 KB |
Output is correct |
19 |
Correct |
121 ms |
1652 KB |
Output is correct |
20 |
Correct |
126 ms |
1752 KB |
Output is correct |
21 |
Correct |
74 ms |
1540 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
40 ms |
852 KB |
Output is correct |
24 |
Correct |
77 ms |
1676 KB |
Output is correct |
25 |
Correct |
9 ms |
416 KB |
Output is correct |
26 |
Correct |
50 ms |
1160 KB |
Output is correct |
27 |
Correct |
59 ms |
1236 KB |
Output is correct |
28 |
Correct |
81 ms |
1760 KB |
Output is correct |
29 |
Correct |
26 ms |
724 KB |
Output is correct |
30 |
Correct |
3 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
1236 KB |
Output is correct |
2 |
Correct |
17 ms |
532 KB |
Output is correct |
3 |
Correct |
42 ms |
852 KB |
Output is correct |
4 |
Correct |
43 ms |
980 KB |
Output is correct |
5 |
Correct |
59 ms |
1124 KB |
Output is correct |
6 |
Correct |
43 ms |
816 KB |
Output is correct |
7 |
Correct |
8 ms |
340 KB |
Output is correct |
8 |
Correct |
39 ms |
828 KB |
Output is correct |
9 |
Correct |
89 ms |
1688 KB |
Output is correct |
10 |
Correct |
53 ms |
1060 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
28 ms |
720 KB |
Output is correct |
27 |
Correct |
67 ms |
1588 KB |
Output is correct |
28 |
Correct |
84 ms |
1816 KB |
Output is correct |
29 |
Correct |
121 ms |
1652 KB |
Output is correct |
30 |
Correct |
126 ms |
1752 KB |
Output is correct |
31 |
Correct |
74 ms |
1540 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
40 ms |
852 KB |
Output is correct |
34 |
Correct |
77 ms |
1676 KB |
Output is correct |
35 |
Correct |
9 ms |
416 KB |
Output is correct |
36 |
Correct |
50 ms |
1160 KB |
Output is correct |
37 |
Correct |
59 ms |
1236 KB |
Output is correct |
38 |
Correct |
81 ms |
1760 KB |
Output is correct |
39 |
Correct |
26 ms |
724 KB |
Output is correct |
40 |
Correct |
3 ms |
212 KB |
Output is correct |
41 |
Correct |
129 ms |
1564 KB |
Output is correct |
42 |
Correct |
106 ms |
4016 KB |
Output is correct |
43 |
Correct |
112 ms |
3476 KB |
Output is correct |
44 |
Correct |
108 ms |
3860 KB |
Output is correct |
45 |
Correct |
102 ms |
4096 KB |
Output is correct |
46 |
Correct |
157 ms |
3952 KB |
Output is correct |
47 |
Correct |
97 ms |
3660 KB |
Output is correct |
48 |
Correct |
107 ms |
3668 KB |
Output is correct |
49 |
Correct |
107 ms |
3532 KB |
Output is correct |
50 |
Correct |
367 ms |
3976 KB |
Output is correct |
51 |
Correct |
382 ms |
4084 KB |
Output is correct |
52 |
Correct |
354 ms |
3844 KB |
Output is correct |
53 |
Correct |
376 ms |
4068 KB |
Output is correct |
54 |
Correct |
352 ms |
3696 KB |
Output is correct |
55 |
Correct |
389 ms |
4216 KB |
Output is correct |
56 |
Correct |
348 ms |
3788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
64 ms |
1236 KB |
Output is correct |
10 |
Correct |
17 ms |
532 KB |
Output is correct |
11 |
Correct |
42 ms |
852 KB |
Output is correct |
12 |
Correct |
43 ms |
980 KB |
Output is correct |
13 |
Correct |
59 ms |
1124 KB |
Output is correct |
14 |
Correct |
43 ms |
816 KB |
Output is correct |
15 |
Correct |
8 ms |
340 KB |
Output is correct |
16 |
Correct |
39 ms |
828 KB |
Output is correct |
17 |
Correct |
89 ms |
1688 KB |
Output is correct |
18 |
Correct |
53 ms |
1060 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
28 ms |
720 KB |
Output is correct |
35 |
Correct |
67 ms |
1588 KB |
Output is correct |
36 |
Correct |
84 ms |
1816 KB |
Output is correct |
37 |
Correct |
121 ms |
1652 KB |
Output is correct |
38 |
Correct |
126 ms |
1752 KB |
Output is correct |
39 |
Correct |
74 ms |
1540 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
40 ms |
852 KB |
Output is correct |
42 |
Correct |
77 ms |
1676 KB |
Output is correct |
43 |
Correct |
9 ms |
416 KB |
Output is correct |
44 |
Correct |
50 ms |
1160 KB |
Output is correct |
45 |
Correct |
59 ms |
1236 KB |
Output is correct |
46 |
Correct |
81 ms |
1760 KB |
Output is correct |
47 |
Correct |
26 ms |
724 KB |
Output is correct |
48 |
Correct |
3 ms |
212 KB |
Output is correct |
49 |
Correct |
129 ms |
1564 KB |
Output is correct |
50 |
Correct |
106 ms |
4016 KB |
Output is correct |
51 |
Correct |
112 ms |
3476 KB |
Output is correct |
52 |
Correct |
108 ms |
3860 KB |
Output is correct |
53 |
Correct |
102 ms |
4096 KB |
Output is correct |
54 |
Correct |
157 ms |
3952 KB |
Output is correct |
55 |
Correct |
97 ms |
3660 KB |
Output is correct |
56 |
Correct |
107 ms |
3668 KB |
Output is correct |
57 |
Correct |
107 ms |
3532 KB |
Output is correct |
58 |
Correct |
367 ms |
3976 KB |
Output is correct |
59 |
Correct |
382 ms |
4084 KB |
Output is correct |
60 |
Correct |
354 ms |
3844 KB |
Output is correct |
61 |
Correct |
376 ms |
4068 KB |
Output is correct |
62 |
Correct |
352 ms |
3696 KB |
Output is correct |
63 |
Correct |
389 ms |
4216 KB |
Output is correct |
64 |
Correct |
348 ms |
3788 KB |
Output is correct |
65 |
Correct |
1 ms |
300 KB |
Output is correct |
66 |
Incorrect |
1 ms |
304 KB |
Output isn't correct |
67 |
Halted |
0 ms |
0 KB |
- |