#include <bits/stdc++.h>
using namespace std;
#define io \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
typedef long long ll;
ll bp(ll n,ll m){
if(m == 0){
return 1;
}
if(m == 1){
return n;
}
if(m%2==0){
return bp(n*n,m/2);
}
return n*bp(n,m-1);
}
const int N = 2505, M = 33, inf = 1e9 + 99;
const ll inff = 1e12;
int main()
{
io;
ll n, k;
cin >> n >> k;
ll res = n * n;
ll a[k][4];
for(int i=0;i<k;i++) {
cin >> a[i][0] >> a[i][1] >> a[i][2] >> a[i][3];
}
for(ll m=1;m<n;m++) {
if(!(n % m)) {
ll tmp = (m * (n / (2 * m)) + min(m, n % (2 * m))) * (n - (m * (n / (2 * m)) + min(m, n % (2 * m)))) + (1LL * m * (n / (2 * m)) + min(1LL * m, 1LL * n % (2 * m))) * (n - (m * (n / (2LL * m)) + min(m, n % (2 * m))));
for(int i=0;i<k;i++) {
ll u = a[i][2] - a[i][0] + 1;
ll x = (m * (a[i][2] / (2 * m)) + min(1LL * m, 1LL * a[i][2] % (2 * m))) - (m * ((a[i][0] - 1) / (2 * m)) + min(1LL * m,1LL * (a[i][0] - 1) % (2LL * m)));
ll v = a[i][3] - a[i][1] + 1;
ll y = (m * (a[i][3] / (2 * m)) + min(1LL * m, 1LL * a[i][3] % (2 * m))) - (1LL * m * ((a[i][1] - 1) / (2 * m)) + min(1LL * m, 1LL * (a[i][1] - 1) % (2LL * m)));;
tmp += 2 * (x * y + (u - x) * (v - y)) - u * v;
}
res = min(res, min(tmp, n * n - tmp));
}
}
cout << res << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 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 |
600 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 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 |
17 ms |
2412 KB |
Output is correct |
2 |
Correct |
5 ms |
1116 KB |
Output is correct |
3 |
Correct |
12 ms |
2396 KB |
Output is correct |
4 |
Correct |
12 ms |
2560 KB |
Output is correct |
5 |
Correct |
15 ms |
3420 KB |
Output is correct |
6 |
Correct |
10 ms |
2164 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
12 ms |
2368 KB |
Output is correct |
9 |
Correct |
26 ms |
5464 KB |
Output is correct |
10 |
Correct |
14 ms |
3160 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 |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
600 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 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 |
0 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 |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
600 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
8 ms |
1116 KB |
Output is correct |
17 |
Correct |
19 ms |
3084 KB |
Output is correct |
18 |
Correct |
25 ms |
3420 KB |
Output is correct |
19 |
Correct |
62 ms |
3164 KB |
Output is correct |
20 |
Correct |
69 ms |
3416 KB |
Output is correct |
21 |
Correct |
17 ms |
2908 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
14 ms |
1628 KB |
Output is correct |
24 |
Correct |
26 ms |
3160 KB |
Output is correct |
25 |
Correct |
3 ms |
604 KB |
Output is correct |
26 |
Correct |
15 ms |
2140 KB |
Output is correct |
27 |
Correct |
20 ms |
2396 KB |
Output is correct |
28 |
Correct |
24 ms |
3420 KB |
Output is correct |
29 |
Correct |
7 ms |
1368 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
2412 KB |
Output is correct |
2 |
Correct |
5 ms |
1116 KB |
Output is correct |
3 |
Correct |
12 ms |
2396 KB |
Output is correct |
4 |
Correct |
12 ms |
2560 KB |
Output is correct |
5 |
Correct |
15 ms |
3420 KB |
Output is correct |
6 |
Correct |
10 ms |
2164 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
12 ms |
2368 KB |
Output is correct |
9 |
Correct |
26 ms |
5464 KB |
Output is correct |
10 |
Correct |
14 ms |
3160 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
600 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
8 ms |
1116 KB |
Output is correct |
27 |
Correct |
19 ms |
3084 KB |
Output is correct |
28 |
Correct |
25 ms |
3420 KB |
Output is correct |
29 |
Correct |
62 ms |
3164 KB |
Output is correct |
30 |
Correct |
69 ms |
3416 KB |
Output is correct |
31 |
Correct |
17 ms |
2908 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
14 ms |
1628 KB |
Output is correct |
34 |
Correct |
26 ms |
3160 KB |
Output is correct |
35 |
Correct |
3 ms |
604 KB |
Output is correct |
36 |
Correct |
15 ms |
2140 KB |
Output is correct |
37 |
Correct |
20 ms |
2396 KB |
Output is correct |
38 |
Correct |
24 ms |
3420 KB |
Output is correct |
39 |
Correct |
7 ms |
1368 KB |
Output is correct |
40 |
Correct |
1 ms |
344 KB |
Output is correct |
41 |
Correct |
60 ms |
4956 KB |
Output is correct |
42 |
Correct |
29 ms |
5460 KB |
Output is correct |
43 |
Correct |
40 ms |
4948 KB |
Output is correct |
44 |
Correct |
29 ms |
5464 KB |
Output is correct |
45 |
Correct |
27 ms |
5712 KB |
Output is correct |
46 |
Correct |
68 ms |
5552 KB |
Output is correct |
47 |
Correct |
23 ms |
4944 KB |
Output is correct |
48 |
Correct |
34 ms |
5212 KB |
Output is correct |
49 |
Correct |
26 ms |
5064 KB |
Output is correct |
50 |
Correct |
258 ms |
5212 KB |
Output is correct |
51 |
Correct |
276 ms |
5972 KB |
Output is correct |
52 |
Correct |
256 ms |
5212 KB |
Output is correct |
53 |
Correct |
277 ms |
5976 KB |
Output is correct |
54 |
Correct |
253 ms |
5204 KB |
Output is correct |
55 |
Correct |
286 ms |
5928 KB |
Output is correct |
56 |
Correct |
248 ms |
5296 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 |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
600 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
17 ms |
2412 KB |
Output is correct |
10 |
Correct |
5 ms |
1116 KB |
Output is correct |
11 |
Correct |
12 ms |
2396 KB |
Output is correct |
12 |
Correct |
12 ms |
2560 KB |
Output is correct |
13 |
Correct |
15 ms |
3420 KB |
Output is correct |
14 |
Correct |
10 ms |
2164 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
12 ms |
2368 KB |
Output is correct |
17 |
Correct |
26 ms |
5464 KB |
Output is correct |
18 |
Correct |
14 ms |
3160 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
600 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
8 ms |
1116 KB |
Output is correct |
35 |
Correct |
19 ms |
3084 KB |
Output is correct |
36 |
Correct |
25 ms |
3420 KB |
Output is correct |
37 |
Correct |
62 ms |
3164 KB |
Output is correct |
38 |
Correct |
69 ms |
3416 KB |
Output is correct |
39 |
Correct |
17 ms |
2908 KB |
Output is correct |
40 |
Correct |
1 ms |
344 KB |
Output is correct |
41 |
Correct |
14 ms |
1628 KB |
Output is correct |
42 |
Correct |
26 ms |
3160 KB |
Output is correct |
43 |
Correct |
3 ms |
604 KB |
Output is correct |
44 |
Correct |
15 ms |
2140 KB |
Output is correct |
45 |
Correct |
20 ms |
2396 KB |
Output is correct |
46 |
Correct |
24 ms |
3420 KB |
Output is correct |
47 |
Correct |
7 ms |
1368 KB |
Output is correct |
48 |
Correct |
1 ms |
344 KB |
Output is correct |
49 |
Correct |
60 ms |
4956 KB |
Output is correct |
50 |
Correct |
29 ms |
5460 KB |
Output is correct |
51 |
Correct |
40 ms |
4948 KB |
Output is correct |
52 |
Correct |
29 ms |
5464 KB |
Output is correct |
53 |
Correct |
27 ms |
5712 KB |
Output is correct |
54 |
Correct |
68 ms |
5552 KB |
Output is correct |
55 |
Correct |
23 ms |
4944 KB |
Output is correct |
56 |
Correct |
34 ms |
5212 KB |
Output is correct |
57 |
Correct |
26 ms |
5064 KB |
Output is correct |
58 |
Correct |
258 ms |
5212 KB |
Output is correct |
59 |
Correct |
276 ms |
5972 KB |
Output is correct |
60 |
Correct |
256 ms |
5212 KB |
Output is correct |
61 |
Correct |
277 ms |
5976 KB |
Output is correct |
62 |
Correct |
253 ms |
5204 KB |
Output is correct |
63 |
Correct |
286 ms |
5928 KB |
Output is correct |
64 |
Correct |
248 ms |
5296 KB |
Output is correct |
65 |
Correct |
0 ms |
348 KB |
Output is correct |
66 |
Correct |
0 ms |
348 KB |
Output is correct |
67 |
Correct |
265 ms |
5540 KB |
Output is correct |
68 |
Correct |
266 ms |
5640 KB |
Output is correct |
69 |
Correct |
233 ms |
4752 KB |
Output is correct |
70 |
Correct |
262 ms |
5212 KB |
Output is correct |
71 |
Correct |
261 ms |
5336 KB |
Output is correct |
72 |
Correct |
252 ms |
5212 KB |
Output is correct |
73 |
Correct |
245 ms |
5116 KB |
Output is correct |
74 |
Correct |
266 ms |
5456 KB |
Output is correct |
75 |
Correct |
260 ms |
5200 KB |
Output is correct |
76 |
Correct |
275 ms |
5456 KB |
Output is correct |
77 |
Correct |
55 ms |
5720 KB |
Output is correct |
78 |
Correct |
28 ms |
5208 KB |
Output is correct |
79 |
Correct |
40 ms |
5356 KB |
Output is correct |
80 |
Correct |
42 ms |
5200 KB |
Output is correct |
81 |
Correct |
39 ms |
4944 KB |
Output is correct |
82 |
Correct |
38 ms |
5464 KB |
Output is correct |
83 |
Correct |
30 ms |
4944 KB |
Output is correct |
84 |
Correct |
174 ms |
5756 KB |
Output is correct |
85 |
Correct |
279 ms |
5852 KB |
Output is correct |
86 |
Correct |
1 ms |
344 KB |
Output is correct |
87 |
Correct |
1 ms |
344 KB |
Output is correct |
88 |
Correct |
289 ms |
5940 KB |
Output is correct |
89 |
Correct |
55 ms |
1372 KB |
Output is correct |
90 |
Correct |
1 ms |
344 KB |
Output is correct |