#include <bits/stdc++.h>
#define pb push_back
using namespace std;
using ll = long long;
const ll INF = 1e18;
const int N = 1e5 + 5;
ll n, m, ans = INF;
vector <int> divs;
ll dp[N];
void add(int num) {
if (num == n) return;
divs.pb(num);
ll len = n / num;
dp[num] = (len * len + 1) / 2 * num * num;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
cin >> n >> m;
for (int i = 1; i * i <= n; i++) {
if (n % i != 0) continue;
add(i);
if (i * i != n) add(n / i);
}
for (int i = 0; i < m; i++) {
int a, b; cin >> a >> b >> a >> b;
// cout << a << " " << b << ": ";
for (auto& num : divs) {
int col = ((a + num - 1) / num + (b + num - 1) / num)&1; // 0 ? black : white
// cout << num << ',' << col << ' ';
dp[num] += col == 1 ? 1 : -1;
}
// cout << '\n';
}
for (auto& num : divs) {
// cout << num << ": " << dp[num] << '\n';
ans = min(ans, min(dp[num], n * n - dp[num]));
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
320 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
1728 KB |
Output is correct |
2 |
Correct |
5 ms |
592 KB |
Output is correct |
3 |
Correct |
12 ms |
1248 KB |
Output is correct |
4 |
Correct |
12 ms |
1076 KB |
Output is correct |
5 |
Correct |
19 ms |
1604 KB |
Output is correct |
6 |
Correct |
11 ms |
1080 KB |
Output is correct |
7 |
Correct |
3 ms |
472 KB |
Output is correct |
8 |
Correct |
11 ms |
1128 KB |
Output is correct |
9 |
Correct |
26 ms |
2336 KB |
Output is correct |
10 |
Correct |
14 ms |
1484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
0 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
324 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
0 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
324 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
8 ms |
716 KB |
Output is correct |
17 |
Correct |
20 ms |
1584 KB |
Output is correct |
18 |
Correct |
26 ms |
1836 KB |
Output is correct |
19 |
Correct |
46 ms |
1700 KB |
Output is correct |
20 |
Correct |
49 ms |
1852 KB |
Output is correct |
21 |
Correct |
19 ms |
1564 KB |
Output is correct |
22 |
Correct |
1 ms |
312 KB |
Output is correct |
23 |
Correct |
12 ms |
956 KB |
Output is correct |
24 |
Correct |
22 ms |
1704 KB |
Output is correct |
25 |
Correct |
3 ms |
460 KB |
Output is correct |
26 |
Correct |
14 ms |
1216 KB |
Output is correct |
27 |
Correct |
20 ms |
1348 KB |
Output is correct |
28 |
Correct |
26 ms |
1732 KB |
Output is correct |
29 |
Correct |
8 ms |
844 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
1728 KB |
Output is correct |
2 |
Correct |
5 ms |
592 KB |
Output is correct |
3 |
Correct |
12 ms |
1248 KB |
Output is correct |
4 |
Correct |
12 ms |
1076 KB |
Output is correct |
5 |
Correct |
19 ms |
1604 KB |
Output is correct |
6 |
Correct |
11 ms |
1080 KB |
Output is correct |
7 |
Correct |
3 ms |
472 KB |
Output is correct |
8 |
Correct |
11 ms |
1128 KB |
Output is correct |
9 |
Correct |
26 ms |
2336 KB |
Output is correct |
10 |
Correct |
14 ms |
1484 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
328 KB |
Output is correct |
13 |
Correct |
0 ms |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
324 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
332 KB |
Output is correct |
22 |
Correct |
0 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
8 ms |
716 KB |
Output is correct |
27 |
Correct |
20 ms |
1584 KB |
Output is correct |
28 |
Correct |
26 ms |
1836 KB |
Output is correct |
29 |
Correct |
46 ms |
1700 KB |
Output is correct |
30 |
Correct |
49 ms |
1852 KB |
Output is correct |
31 |
Correct |
19 ms |
1564 KB |
Output is correct |
32 |
Correct |
1 ms |
312 KB |
Output is correct |
33 |
Correct |
12 ms |
956 KB |
Output is correct |
34 |
Correct |
22 ms |
1704 KB |
Output is correct |
35 |
Correct |
3 ms |
460 KB |
Output is correct |
36 |
Correct |
14 ms |
1216 KB |
Output is correct |
37 |
Correct |
20 ms |
1348 KB |
Output is correct |
38 |
Correct |
26 ms |
1732 KB |
Output is correct |
39 |
Correct |
8 ms |
844 KB |
Output is correct |
40 |
Correct |
2 ms |
332 KB |
Output is correct |
41 |
Correct |
46 ms |
2244 KB |
Output is correct |
42 |
Correct |
29 ms |
2500 KB |
Output is correct |
43 |
Correct |
34 ms |
2240 KB |
Output is correct |
44 |
Correct |
27 ms |
2376 KB |
Output is correct |
45 |
Correct |
28 ms |
2592 KB |
Output is correct |
46 |
Correct |
50 ms |
2504 KB |
Output is correct |
47 |
Correct |
29 ms |
2332 KB |
Output is correct |
48 |
Correct |
38 ms |
2348 KB |
Output is correct |
49 |
Correct |
27 ms |
2248 KB |
Output is correct |
50 |
Correct |
171 ms |
2548 KB |
Output is correct |
51 |
Correct |
172 ms |
2676 KB |
Output is correct |
52 |
Correct |
157 ms |
2424 KB |
Output is correct |
53 |
Correct |
175 ms |
2676 KB |
Output is correct |
54 |
Correct |
170 ms |
2436 KB |
Output is correct |
55 |
Correct |
178 ms |
2672 KB |
Output is correct |
56 |
Correct |
161 ms |
2428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
320 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
17 ms |
1728 KB |
Output is correct |
10 |
Correct |
5 ms |
592 KB |
Output is correct |
11 |
Correct |
12 ms |
1248 KB |
Output is correct |
12 |
Correct |
12 ms |
1076 KB |
Output is correct |
13 |
Correct |
19 ms |
1604 KB |
Output is correct |
14 |
Correct |
11 ms |
1080 KB |
Output is correct |
15 |
Correct |
3 ms |
472 KB |
Output is correct |
16 |
Correct |
11 ms |
1128 KB |
Output is correct |
17 |
Correct |
26 ms |
2336 KB |
Output is correct |
18 |
Correct |
14 ms |
1484 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
328 KB |
Output is correct |
21 |
Correct |
0 ms |
320 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
0 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
0 ms |
324 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
0 ms |
332 KB |
Output is correct |
30 |
Correct |
0 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
8 ms |
716 KB |
Output is correct |
35 |
Correct |
20 ms |
1584 KB |
Output is correct |
36 |
Correct |
26 ms |
1836 KB |
Output is correct |
37 |
Correct |
46 ms |
1700 KB |
Output is correct |
38 |
Correct |
49 ms |
1852 KB |
Output is correct |
39 |
Correct |
19 ms |
1564 KB |
Output is correct |
40 |
Correct |
1 ms |
312 KB |
Output is correct |
41 |
Correct |
12 ms |
956 KB |
Output is correct |
42 |
Correct |
22 ms |
1704 KB |
Output is correct |
43 |
Correct |
3 ms |
460 KB |
Output is correct |
44 |
Correct |
14 ms |
1216 KB |
Output is correct |
45 |
Correct |
20 ms |
1348 KB |
Output is correct |
46 |
Correct |
26 ms |
1732 KB |
Output is correct |
47 |
Correct |
8 ms |
844 KB |
Output is correct |
48 |
Correct |
2 ms |
332 KB |
Output is correct |
49 |
Correct |
46 ms |
2244 KB |
Output is correct |
50 |
Correct |
29 ms |
2500 KB |
Output is correct |
51 |
Correct |
34 ms |
2240 KB |
Output is correct |
52 |
Correct |
27 ms |
2376 KB |
Output is correct |
53 |
Correct |
28 ms |
2592 KB |
Output is correct |
54 |
Correct |
50 ms |
2504 KB |
Output is correct |
55 |
Correct |
29 ms |
2332 KB |
Output is correct |
56 |
Correct |
38 ms |
2348 KB |
Output is correct |
57 |
Correct |
27 ms |
2248 KB |
Output is correct |
58 |
Correct |
171 ms |
2548 KB |
Output is correct |
59 |
Correct |
172 ms |
2676 KB |
Output is correct |
60 |
Correct |
157 ms |
2424 KB |
Output is correct |
61 |
Correct |
175 ms |
2676 KB |
Output is correct |
62 |
Correct |
170 ms |
2436 KB |
Output is correct |
63 |
Correct |
178 ms |
2672 KB |
Output is correct |
64 |
Correct |
161 ms |
2428 KB |
Output is correct |
65 |
Correct |
1 ms |
204 KB |
Output is correct |
66 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
67 |
Halted |
0 ms |
0 KB |
- |