#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
typedef long long ll;
typedef pair<int,int> pii;
int main(){
ll n, k;
cin >> n >> k;
if(k == 0){
ll ans = n*n/2;
for(ll i=2; i<=n; i++) if(n%i == 0) ans = min(ans, (i*i/2)*(n/i)*(n/i));
cout << ans << "\n";
return 0;
}
vector<pii> rec(k);
for(int i=0; i<k; i++) cin >> rec[i].f >> rec[i].s >> rec[i].f >> rec[i].s;
vector<ll> div;
for(ll i=1; i*i<=n; i++){
if(n%i == 0){
div.push_back(i);
if(n/i != i) div.push_back(n/i);
}
}
ll ans = n*n;
for(auto len : div){
if(len == n) continue;
ll a = 0, b = 0;
for(auto r : rec){
int i = (r.f + len - 1)/len;
int j = (r.s + len - 1)/len;
if((i+j)%2 == 0) a++;
else b++;
}
ll qtdp = ((n/len)*(n/len)+1)/2*len*len;
ll qtdb = n*n - qtdp;
ans = min(ans, qtdp - a + b);
ans = min(ans, qtdb - b + a);
}
cout << ans << "\n";
/*
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
*/
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
148 ms |
2328 KB |
Output is correct |
2 |
Correct |
34 ms |
768 KB |
Output is correct |
3 |
Correct |
89 ms |
1528 KB |
Output is correct |
4 |
Correct |
86 ms |
1528 KB |
Output is correct |
5 |
Correct |
122 ms |
2064 KB |
Output is correct |
6 |
Correct |
78 ms |
1400 KB |
Output is correct |
7 |
Correct |
17 ms |
512 KB |
Output is correct |
8 |
Correct |
78 ms |
1472 KB |
Output is correct |
9 |
Correct |
198 ms |
3192 KB |
Output is correct |
10 |
Correct |
111 ms |
1912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
47 ms |
1016 KB |
Output is correct |
17 |
Correct |
142 ms |
2296 KB |
Output is correct |
18 |
Correct |
173 ms |
2680 KB |
Output is correct |
19 |
Correct |
190 ms |
2424 KB |
Output is correct |
20 |
Correct |
208 ms |
2680 KB |
Output is correct |
21 |
Correct |
139 ms |
2272 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
77 ms |
1276 KB |
Output is correct |
24 |
Correct |
155 ms |
2424 KB |
Output is correct |
25 |
Correct |
16 ms |
512 KB |
Output is correct |
26 |
Correct |
100 ms |
1700 KB |
Output is correct |
27 |
Correct |
119 ms |
1912 KB |
Output is correct |
28 |
Correct |
165 ms |
2552 KB |
Output is correct |
29 |
Correct |
57 ms |
1144 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
148 ms |
2328 KB |
Output is correct |
2 |
Correct |
34 ms |
768 KB |
Output is correct |
3 |
Correct |
89 ms |
1528 KB |
Output is correct |
4 |
Correct |
86 ms |
1528 KB |
Output is correct |
5 |
Correct |
122 ms |
2064 KB |
Output is correct |
6 |
Correct |
78 ms |
1400 KB |
Output is correct |
7 |
Correct |
17 ms |
512 KB |
Output is correct |
8 |
Correct |
78 ms |
1472 KB |
Output is correct |
9 |
Correct |
198 ms |
3192 KB |
Output is correct |
10 |
Correct |
111 ms |
1912 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
1 ms |
256 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
256 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
47 ms |
1016 KB |
Output is correct |
27 |
Correct |
142 ms |
2296 KB |
Output is correct |
28 |
Correct |
173 ms |
2680 KB |
Output is correct |
29 |
Correct |
190 ms |
2424 KB |
Output is correct |
30 |
Correct |
208 ms |
2680 KB |
Output is correct |
31 |
Correct |
139 ms |
2272 KB |
Output is correct |
32 |
Correct |
2 ms |
384 KB |
Output is correct |
33 |
Correct |
77 ms |
1276 KB |
Output is correct |
34 |
Correct |
155 ms |
2424 KB |
Output is correct |
35 |
Correct |
16 ms |
512 KB |
Output is correct |
36 |
Correct |
100 ms |
1700 KB |
Output is correct |
37 |
Correct |
119 ms |
1912 KB |
Output is correct |
38 |
Correct |
165 ms |
2552 KB |
Output is correct |
39 |
Correct |
57 ms |
1144 KB |
Output is correct |
40 |
Correct |
5 ms |
384 KB |
Output is correct |
41 |
Correct |
221 ms |
2936 KB |
Output is correct |
42 |
Correct |
213 ms |
3320 KB |
Output is correct |
43 |
Correct |
204 ms |
2936 KB |
Output is correct |
44 |
Correct |
207 ms |
3248 KB |
Output is correct |
45 |
Correct |
225 ms |
3448 KB |
Output is correct |
46 |
Correct |
245 ms |
3320 KB |
Output is correct |
47 |
Correct |
198 ms |
3192 KB |
Output is correct |
48 |
Correct |
206 ms |
3064 KB |
Output is correct |
49 |
Correct |
193 ms |
2940 KB |
Output is correct |
50 |
Correct |
411 ms |
3244 KB |
Output is correct |
51 |
Correct |
440 ms |
3448 KB |
Output is correct |
52 |
Correct |
406 ms |
3320 KB |
Output is correct |
53 |
Correct |
435 ms |
3448 KB |
Output is correct |
54 |
Correct |
400 ms |
3320 KB |
Output is correct |
55 |
Correct |
452 ms |
3576 KB |
Output is correct |
56 |
Correct |
394 ms |
3192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
148 ms |
2328 KB |
Output is correct |
10 |
Correct |
34 ms |
768 KB |
Output is correct |
11 |
Correct |
89 ms |
1528 KB |
Output is correct |
12 |
Correct |
86 ms |
1528 KB |
Output is correct |
13 |
Correct |
122 ms |
2064 KB |
Output is correct |
14 |
Correct |
78 ms |
1400 KB |
Output is correct |
15 |
Correct |
17 ms |
512 KB |
Output is correct |
16 |
Correct |
78 ms |
1472 KB |
Output is correct |
17 |
Correct |
198 ms |
3192 KB |
Output is correct |
18 |
Correct |
111 ms |
1912 KB |
Output is correct |
19 |
Correct |
1 ms |
256 KB |
Output is correct |
20 |
Correct |
1 ms |
256 KB |
Output is correct |
21 |
Correct |
1 ms |
256 KB |
Output is correct |
22 |
Correct |
3 ms |
384 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
256 KB |
Output is correct |
29 |
Correct |
2 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
2 ms |
384 KB |
Output is correct |
32 |
Correct |
2 ms |
384 KB |
Output is correct |
33 |
Correct |
2 ms |
384 KB |
Output is correct |
34 |
Correct |
47 ms |
1016 KB |
Output is correct |
35 |
Correct |
142 ms |
2296 KB |
Output is correct |
36 |
Correct |
173 ms |
2680 KB |
Output is correct |
37 |
Correct |
190 ms |
2424 KB |
Output is correct |
38 |
Correct |
208 ms |
2680 KB |
Output is correct |
39 |
Correct |
139 ms |
2272 KB |
Output is correct |
40 |
Correct |
2 ms |
384 KB |
Output is correct |
41 |
Correct |
77 ms |
1276 KB |
Output is correct |
42 |
Correct |
155 ms |
2424 KB |
Output is correct |
43 |
Correct |
16 ms |
512 KB |
Output is correct |
44 |
Correct |
100 ms |
1700 KB |
Output is correct |
45 |
Correct |
119 ms |
1912 KB |
Output is correct |
46 |
Correct |
165 ms |
2552 KB |
Output is correct |
47 |
Correct |
57 ms |
1144 KB |
Output is correct |
48 |
Correct |
5 ms |
384 KB |
Output is correct |
49 |
Correct |
221 ms |
2936 KB |
Output is correct |
50 |
Correct |
213 ms |
3320 KB |
Output is correct |
51 |
Correct |
204 ms |
2936 KB |
Output is correct |
52 |
Correct |
207 ms |
3248 KB |
Output is correct |
53 |
Correct |
225 ms |
3448 KB |
Output is correct |
54 |
Correct |
245 ms |
3320 KB |
Output is correct |
55 |
Correct |
198 ms |
3192 KB |
Output is correct |
56 |
Correct |
206 ms |
3064 KB |
Output is correct |
57 |
Correct |
193 ms |
2940 KB |
Output is correct |
58 |
Correct |
411 ms |
3244 KB |
Output is correct |
59 |
Correct |
440 ms |
3448 KB |
Output is correct |
60 |
Correct |
406 ms |
3320 KB |
Output is correct |
61 |
Correct |
435 ms |
3448 KB |
Output is correct |
62 |
Correct |
400 ms |
3320 KB |
Output is correct |
63 |
Correct |
452 ms |
3576 KB |
Output is correct |
64 |
Correct |
394 ms |
3192 KB |
Output is correct |
65 |
Correct |
0 ms |
256 KB |
Output is correct |
66 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
67 |
Halted |
0 ms |
0 KB |
- |