#include<bits/stdc++.h>
#include<fstream>
using namespace std;
#define sz(a) (int)a.size()
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mpp make_pair
const ld PI = 3.14159265359, prec = 1e-9;;
//using u128 = __uint128_t;
//const int x[4] = {1, 0, -1, 0};
//const int y[4] = {0, -1, 0, 1};
const ll mod = 1e9 + 7, pr = 31;
const int mxn = 5e5 + 5, mxq = 1e5 + 5, sq = 450, mxv = 5e4 + 1;
//const int base = (1 <<18);
const ll inf = 1e10 + 5, neg = -69420, inf2 = 1e14;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// have fun!
ll n, k;
ll ans = inf;
ll x[mxn + 1], y[mxn + 1], x2[mxn + 1], y2[mxn + 1];
void solve(int cand){
ll odd = 0, even = 0;
for(int i = 1; i <= k; i++){
ll sm = x[i] / cand + y[i] / cand;
if(sm & 1)odd++;
else even++;
}
ll totodd = 0, toteven = 0;
if((n / cand) & 1){
toteven = (n * n / (cand * cand) + 1) / 2 * cand * cand;
totodd = (n * n / (cand * cand)) / 2 * cand * cand;
}else{
toteven = (n * n / (cand * cand)) / 2 * cand * cand;
totodd = (n * n / (cand * cand)) / 2 * cand * cand;
}
//cout << cand << " " << abs(toteven - even) + k - even << " " << abs(totodd - odd) + k - odd << "\n";
ans = min(ans, min(abs(toteven - even) + k - even, abs(totodd - odd) + k - odd));
}
void solve(){
cin >> n >> k;
for(int i = 1; i <= k; i++){
cin >> x[i] >> y[i] >> x2[i] >> y2[i]; --x[i]; --y[i]; --x2[i]; --y2[i];
}
for(int i = 1; i < n; i++){
if(n % i == 0){
solve(i);
}
}
cout << ans;
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("netw.inp", "r", stdin);
//freopen("netw.out", "w", stdout)
int tt; tt = 1;
while(tt--){
solve();
}
return(0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
12380 KB |
Output is correct |
2 |
Correct |
5 ms |
7004 KB |
Output is correct |
3 |
Correct |
11 ms |
9560 KB |
Output is correct |
4 |
Correct |
15 ms |
9564 KB |
Output is correct |
5 |
Correct |
16 ms |
12428 KB |
Output is correct |
6 |
Correct |
11 ms |
9560 KB |
Output is correct |
7 |
Correct |
3 ms |
6748 KB |
Output is correct |
8 |
Correct |
11 ms |
9448 KB |
Output is correct |
9 |
Correct |
27 ms |
15036 KB |
Output is correct |
10 |
Correct |
18 ms |
11896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6608 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6488 KB |
Output is correct |
6 |
Correct |
2 ms |
6616 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6488 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6616 KB |
Output is correct |
11 |
Correct |
1 ms |
6748 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
2 ms |
6492 KB |
Output is correct |
14 |
Correct |
2 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6608 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6488 KB |
Output is correct |
6 |
Correct |
2 ms |
6616 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6488 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6616 KB |
Output is correct |
11 |
Correct |
1 ms |
6748 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
2 ms |
6492 KB |
Output is correct |
14 |
Correct |
2 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
8 ms |
9052 KB |
Output is correct |
17 |
Correct |
22 ms |
14092 KB |
Output is correct |
18 |
Correct |
24 ms |
16476 KB |
Output is correct |
19 |
Correct |
49 ms |
14172 KB |
Output is correct |
20 |
Correct |
58 ms |
16584 KB |
Output is correct |
21 |
Correct |
19 ms |
14172 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
13 ms |
9548 KB |
Output is correct |
24 |
Correct |
23 ms |
14172 KB |
Output is correct |
25 |
Correct |
4 ms |
6748 KB |
Output is correct |
26 |
Correct |
15 ms |
11828 KB |
Output is correct |
27 |
Correct |
18 ms |
11868 KB |
Output is correct |
28 |
Correct |
24 ms |
14428 KB |
Output is correct |
29 |
Correct |
11 ms |
9180 KB |
Output is correct |
30 |
Correct |
2 ms |
6648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
12380 KB |
Output is correct |
2 |
Correct |
5 ms |
7004 KB |
Output is correct |
3 |
Correct |
11 ms |
9560 KB |
Output is correct |
4 |
Correct |
15 ms |
9564 KB |
Output is correct |
5 |
Correct |
16 ms |
12428 KB |
Output is correct |
6 |
Correct |
11 ms |
9560 KB |
Output is correct |
7 |
Correct |
3 ms |
6748 KB |
Output is correct |
8 |
Correct |
11 ms |
9448 KB |
Output is correct |
9 |
Correct |
27 ms |
15036 KB |
Output is correct |
10 |
Correct |
18 ms |
11896 KB |
Output is correct |
11 |
Correct |
1 ms |
6608 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6488 KB |
Output is correct |
16 |
Correct |
2 ms |
6616 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6488 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6616 KB |
Output is correct |
21 |
Correct |
1 ms |
6748 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
2 ms |
6492 KB |
Output is correct |
24 |
Correct |
2 ms |
6492 KB |
Output is correct |
25 |
Correct |
1 ms |
6492 KB |
Output is correct |
26 |
Correct |
8 ms |
9052 KB |
Output is correct |
27 |
Correct |
22 ms |
14092 KB |
Output is correct |
28 |
Correct |
24 ms |
16476 KB |
Output is correct |
29 |
Correct |
49 ms |
14172 KB |
Output is correct |
30 |
Correct |
58 ms |
16584 KB |
Output is correct |
31 |
Correct |
19 ms |
14172 KB |
Output is correct |
32 |
Correct |
1 ms |
6492 KB |
Output is correct |
33 |
Correct |
13 ms |
9548 KB |
Output is correct |
34 |
Correct |
23 ms |
14172 KB |
Output is correct |
35 |
Correct |
4 ms |
6748 KB |
Output is correct |
36 |
Correct |
15 ms |
11828 KB |
Output is correct |
37 |
Correct |
18 ms |
11868 KB |
Output is correct |
38 |
Correct |
24 ms |
14428 KB |
Output is correct |
39 |
Correct |
11 ms |
9180 KB |
Output is correct |
40 |
Correct |
2 ms |
6648 KB |
Output is correct |
41 |
Correct |
47 ms |
14860 KB |
Output is correct |
42 |
Correct |
30 ms |
15128 KB |
Output is correct |
43 |
Correct |
33 ms |
14748 KB |
Output is correct |
44 |
Correct |
34 ms |
14940 KB |
Output is correct |
45 |
Correct |
26 ms |
17244 KB |
Output is correct |
46 |
Correct |
54 ms |
14984 KB |
Output is correct |
47 |
Correct |
23 ms |
14928 KB |
Output is correct |
48 |
Correct |
30 ms |
14860 KB |
Output is correct |
49 |
Correct |
24 ms |
14716 KB |
Output is correct |
50 |
Correct |
181 ms |
15116 KB |
Output is correct |
51 |
Correct |
195 ms |
17312 KB |
Output is correct |
52 |
Correct |
183 ms |
15092 KB |
Output is correct |
53 |
Correct |
191 ms |
15112 KB |
Output is correct |
54 |
Correct |
180 ms |
15072 KB |
Output is correct |
55 |
Correct |
199 ms |
17492 KB |
Output is correct |
56 |
Correct |
180 ms |
15004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
628 KB |
Output is correct |
9 |
Correct |
17 ms |
12380 KB |
Output is correct |
10 |
Correct |
5 ms |
7004 KB |
Output is correct |
11 |
Correct |
11 ms |
9560 KB |
Output is correct |
12 |
Correct |
15 ms |
9564 KB |
Output is correct |
13 |
Correct |
16 ms |
12428 KB |
Output is correct |
14 |
Correct |
11 ms |
9560 KB |
Output is correct |
15 |
Correct |
3 ms |
6748 KB |
Output is correct |
16 |
Correct |
11 ms |
9448 KB |
Output is correct |
17 |
Correct |
27 ms |
15036 KB |
Output is correct |
18 |
Correct |
18 ms |
11896 KB |
Output is correct |
19 |
Correct |
1 ms |
6608 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
1 ms |
6488 KB |
Output is correct |
24 |
Correct |
2 ms |
6616 KB |
Output is correct |
25 |
Correct |
1 ms |
6492 KB |
Output is correct |
26 |
Correct |
1 ms |
6488 KB |
Output is correct |
27 |
Correct |
1 ms |
6492 KB |
Output is correct |
28 |
Correct |
1 ms |
6616 KB |
Output is correct |
29 |
Correct |
1 ms |
6748 KB |
Output is correct |
30 |
Correct |
1 ms |
6492 KB |
Output is correct |
31 |
Correct |
2 ms |
6492 KB |
Output is correct |
32 |
Correct |
2 ms |
6492 KB |
Output is correct |
33 |
Correct |
1 ms |
6492 KB |
Output is correct |
34 |
Correct |
8 ms |
9052 KB |
Output is correct |
35 |
Correct |
22 ms |
14092 KB |
Output is correct |
36 |
Correct |
24 ms |
16476 KB |
Output is correct |
37 |
Correct |
49 ms |
14172 KB |
Output is correct |
38 |
Correct |
58 ms |
16584 KB |
Output is correct |
39 |
Correct |
19 ms |
14172 KB |
Output is correct |
40 |
Correct |
1 ms |
6492 KB |
Output is correct |
41 |
Correct |
13 ms |
9548 KB |
Output is correct |
42 |
Correct |
23 ms |
14172 KB |
Output is correct |
43 |
Correct |
4 ms |
6748 KB |
Output is correct |
44 |
Correct |
15 ms |
11828 KB |
Output is correct |
45 |
Correct |
18 ms |
11868 KB |
Output is correct |
46 |
Correct |
24 ms |
14428 KB |
Output is correct |
47 |
Correct |
11 ms |
9180 KB |
Output is correct |
48 |
Correct |
2 ms |
6648 KB |
Output is correct |
49 |
Correct |
47 ms |
14860 KB |
Output is correct |
50 |
Correct |
30 ms |
15128 KB |
Output is correct |
51 |
Correct |
33 ms |
14748 KB |
Output is correct |
52 |
Correct |
34 ms |
14940 KB |
Output is correct |
53 |
Correct |
26 ms |
17244 KB |
Output is correct |
54 |
Correct |
54 ms |
14984 KB |
Output is correct |
55 |
Correct |
23 ms |
14928 KB |
Output is correct |
56 |
Correct |
30 ms |
14860 KB |
Output is correct |
57 |
Correct |
24 ms |
14716 KB |
Output is correct |
58 |
Correct |
181 ms |
15116 KB |
Output is correct |
59 |
Correct |
195 ms |
17312 KB |
Output is correct |
60 |
Correct |
183 ms |
15092 KB |
Output is correct |
61 |
Correct |
191 ms |
15112 KB |
Output is correct |
62 |
Correct |
180 ms |
15072 KB |
Output is correct |
63 |
Correct |
199 ms |
17492 KB |
Output is correct |
64 |
Correct |
180 ms |
15004 KB |
Output is correct |
65 |
Correct |
1 ms |
6492 KB |
Output is correct |
66 |
Incorrect |
1 ms |
6616 KB |
Output isn't correct |
67 |
Halted |
0 ms |
0 KB |
- |