#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll, ll>
#define oo 1e12
#define int ll
int n, k;
const int MAX = 1e5 + 5;
vector<pii> black;
vector<int> s;
void solve(){
cin >> n >> k;
for(int i = 1; i <= k; i++){
int a, b; cin >> a >> b >> a >> b;
black.push_back({a, b});
}
s.push_back(1);
for(int d = 2; d * d <= n; d++){
if(n % d == 0){
s.push_back(d);
if(n / d != d){
s.push_back(n / d);
}
}
}
int ans = oo;
for(int a : s){
int tmp1 = ((n / a) * (n / a) + 1) / 2 * a * a;
int tmp2 = ((n / a) * (n / a)) / 2 * a * a;
for(pii b : black){
int x = (b.first - 1) / a + 1;
int y = (b.second - 1) / a + 1;
if(x % 2 == y % 2){
tmp1--;
tmp2++;
}
else{
tmp1++;
tmp2--;
}
}
ans = min(tmp1, ans);
ans = min(tmp2, ans);
}
cout << ans << '\n';
}
signed main(){
int t = 1;
while(t--){
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
1484 KB |
Output is correct |
2 |
Correct |
14 ms |
1240 KB |
Output is correct |
3 |
Correct |
32 ms |
2328 KB |
Output is correct |
4 |
Correct |
31 ms |
2248 KB |
Output is correct |
5 |
Correct |
43 ms |
2340 KB |
Output is correct |
6 |
Correct |
27 ms |
2252 KB |
Output is correct |
7 |
Correct |
6 ms |
604 KB |
Output is correct |
8 |
Correct |
28 ms |
2248 KB |
Output is correct |
9 |
Correct |
73 ms |
4224 KB |
Output is correct |
10 |
Correct |
39 ms |
2184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
0 ms |
360 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
0 ms |
360 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 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 |
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 |
18 ms |
1236 KB |
Output is correct |
17 |
Correct |
52 ms |
2500 KB |
Output is correct |
18 |
Correct |
62 ms |
2500 KB |
Output is correct |
19 |
Correct |
85 ms |
2512 KB |
Output is correct |
20 |
Correct |
93 ms |
2504 KB |
Output is correct |
21 |
Correct |
48 ms |
2592 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
29 ms |
1512 KB |
Output is correct |
24 |
Correct |
56 ms |
2536 KB |
Output is correct |
25 |
Correct |
6 ms |
604 KB |
Output is correct |
26 |
Correct |
35 ms |
1524 KB |
Output is correct |
27 |
Correct |
45 ms |
2596 KB |
Output is correct |
28 |
Correct |
59 ms |
3632 KB |
Output is correct |
29 |
Correct |
21 ms |
1480 KB |
Output is correct |
30 |
Correct |
2 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
1484 KB |
Output is correct |
2 |
Correct |
14 ms |
1240 KB |
Output is correct |
3 |
Correct |
32 ms |
2328 KB |
Output is correct |
4 |
Correct |
31 ms |
2248 KB |
Output is correct |
5 |
Correct |
43 ms |
2340 KB |
Output is correct |
6 |
Correct |
27 ms |
2252 KB |
Output is correct |
7 |
Correct |
6 ms |
604 KB |
Output is correct |
8 |
Correct |
28 ms |
2248 KB |
Output is correct |
9 |
Correct |
73 ms |
4224 KB |
Output is correct |
10 |
Correct |
39 ms |
2184 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 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 |
0 ms |
360 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
18 ms |
1236 KB |
Output is correct |
27 |
Correct |
52 ms |
2500 KB |
Output is correct |
28 |
Correct |
62 ms |
2500 KB |
Output is correct |
29 |
Correct |
85 ms |
2512 KB |
Output is correct |
30 |
Correct |
93 ms |
2504 KB |
Output is correct |
31 |
Correct |
48 ms |
2592 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
29 ms |
1512 KB |
Output is correct |
34 |
Correct |
56 ms |
2536 KB |
Output is correct |
35 |
Correct |
6 ms |
604 KB |
Output is correct |
36 |
Correct |
35 ms |
1524 KB |
Output is correct |
37 |
Correct |
45 ms |
2596 KB |
Output is correct |
38 |
Correct |
59 ms |
3632 KB |
Output is correct |
39 |
Correct |
21 ms |
1480 KB |
Output is correct |
40 |
Correct |
2 ms |
344 KB |
Output is correct |
41 |
Correct |
92 ms |
3780 KB |
Output is correct |
42 |
Correct |
78 ms |
3840 KB |
Output is correct |
43 |
Correct |
79 ms |
3696 KB |
Output is correct |
44 |
Correct |
76 ms |
3560 KB |
Output is correct |
45 |
Correct |
79 ms |
3780 KB |
Output is correct |
46 |
Correct |
103 ms |
3664 KB |
Output is correct |
47 |
Correct |
68 ms |
3780 KB |
Output is correct |
48 |
Correct |
80 ms |
4016 KB |
Output is correct |
49 |
Correct |
69 ms |
3668 KB |
Output is correct |
50 |
Correct |
237 ms |
3860 KB |
Output is correct |
51 |
Correct |
252 ms |
4064 KB |
Output is correct |
52 |
Correct |
236 ms |
3780 KB |
Output is correct |
53 |
Correct |
250 ms |
3780 KB |
Output is correct |
54 |
Correct |
231 ms |
3780 KB |
Output is correct |
55 |
Correct |
260 ms |
3828 KB |
Output is correct |
56 |
Correct |
225 ms |
3524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
55 ms |
1484 KB |
Output is correct |
10 |
Correct |
14 ms |
1240 KB |
Output is correct |
11 |
Correct |
32 ms |
2328 KB |
Output is correct |
12 |
Correct |
31 ms |
2248 KB |
Output is correct |
13 |
Correct |
43 ms |
2340 KB |
Output is correct |
14 |
Correct |
27 ms |
2252 KB |
Output is correct |
15 |
Correct |
6 ms |
604 KB |
Output is correct |
16 |
Correct |
28 ms |
2248 KB |
Output is correct |
17 |
Correct |
73 ms |
4224 KB |
Output is correct |
18 |
Correct |
39 ms |
2184 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 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 |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
360 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
18 ms |
1236 KB |
Output is correct |
35 |
Correct |
52 ms |
2500 KB |
Output is correct |
36 |
Correct |
62 ms |
2500 KB |
Output is correct |
37 |
Correct |
85 ms |
2512 KB |
Output is correct |
38 |
Correct |
93 ms |
2504 KB |
Output is correct |
39 |
Correct |
48 ms |
2592 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
29 ms |
1512 KB |
Output is correct |
42 |
Correct |
56 ms |
2536 KB |
Output is correct |
43 |
Correct |
6 ms |
604 KB |
Output is correct |
44 |
Correct |
35 ms |
1524 KB |
Output is correct |
45 |
Correct |
45 ms |
2596 KB |
Output is correct |
46 |
Correct |
59 ms |
3632 KB |
Output is correct |
47 |
Correct |
21 ms |
1480 KB |
Output is correct |
48 |
Correct |
2 ms |
344 KB |
Output is correct |
49 |
Correct |
92 ms |
3780 KB |
Output is correct |
50 |
Correct |
78 ms |
3840 KB |
Output is correct |
51 |
Correct |
79 ms |
3696 KB |
Output is correct |
52 |
Correct |
76 ms |
3560 KB |
Output is correct |
53 |
Correct |
79 ms |
3780 KB |
Output is correct |
54 |
Correct |
103 ms |
3664 KB |
Output is correct |
55 |
Correct |
68 ms |
3780 KB |
Output is correct |
56 |
Correct |
80 ms |
4016 KB |
Output is correct |
57 |
Correct |
69 ms |
3668 KB |
Output is correct |
58 |
Correct |
237 ms |
3860 KB |
Output is correct |
59 |
Correct |
252 ms |
4064 KB |
Output is correct |
60 |
Correct |
236 ms |
3780 KB |
Output is correct |
61 |
Correct |
250 ms |
3780 KB |
Output is correct |
62 |
Correct |
231 ms |
3780 KB |
Output is correct |
63 |
Correct |
260 ms |
3828 KB |
Output is correct |
64 |
Correct |
225 ms |
3524 KB |
Output is correct |
65 |
Correct |
0 ms |
348 KB |
Output is correct |
66 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
67 |
Halted |
0 ms |
0 KB |
- |