#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;
int 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(int 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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
2412 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
8 ms |
1112 KB |
Output is correct |
17 |
Correct |
20 ms |
3088 KB |
Output is correct |
18 |
Correct |
28 ms |
3420 KB |
Output is correct |
19 |
Correct |
85 ms |
3164 KB |
Output is correct |
20 |
Correct |
99 ms |
3416 KB |
Output is correct |
21 |
Correct |
19 ms |
2980 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
18 ms |
1780 KB |
Output is correct |
24 |
Correct |
26 ms |
3160 KB |
Output is correct |
25 |
Correct |
4 ms |
604 KB |
Output is correct |
26 |
Correct |
19 ms |
2140 KB |
Output is correct |
27 |
Correct |
25 ms |
2392 KB |
Output is correct |
28 |
Correct |
27 ms |
3668 KB |
Output is correct |
29 |
Correct |
8 ms |
1368 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
2412 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
Incorrect |
17 ms |
2412 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |