#include <bits/stdc++.h>
using namespace std;
template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl
using ll = long long;
const ll inf = 1e18;
ll n,k;
vector<pair<ll,ll>> a;
ll solve(ll x) {
map<ll,ll> dp;
for (auto p: a) {
dp[(p.first/x + p.second/x)%2]++;
}
ll res = inf;
ll cells = (n/x)*(n/x);
ll area = x*x;
//even black
{
ll sq = (cells/2 + (n/x)%2);
ll cur = (sq*area - dp[0]) + dp[1];
res = min(res, cur);
}
//odd black
{
ll sq = cells/2;
ll cur = (sq*area - dp[1]) + dp[0];
res = min(res, cur);
}
return res;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n>>k;
a.resize(k);
for (int i=0; i<k; i++) {
cin>>a[i].first>>a[i].second;
cin>>a[i].first>>a[i].second;
--a[i].first; --a[i].second;
}
ll res = inf;
for (ll i=1; i<n; i++) {
if (n%i==0) {
ll cur=solve(i);
//cout<<i<<": "<<cur<<endl;
res = min(res, cur);
}
}
cout<<res<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
2816 KB |
Output is correct |
2 |
Correct |
9 ms |
1004 KB |
Output is correct |
3 |
Correct |
18 ms |
1900 KB |
Output is correct |
4 |
Correct |
19 ms |
1900 KB |
Output is correct |
5 |
Correct |
25 ms |
2412 KB |
Output is correct |
6 |
Correct |
16 ms |
1644 KB |
Output is correct |
7 |
Correct |
4 ms |
620 KB |
Output is correct |
8 |
Correct |
16 ms |
1644 KB |
Output is correct |
9 |
Correct |
41 ms |
3948 KB |
Output is correct |
10 |
Correct |
23 ms |
2284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
36 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
35 ms |
364 KB |
Output is correct |
12 |
Correct |
34 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
36 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
35 ms |
364 KB |
Output is correct |
12 |
Correct |
34 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
11 ms |
1280 KB |
Output is correct |
17 |
Correct |
31 ms |
3052 KB |
Output is correct |
18 |
Correct |
39 ms |
3436 KB |
Output is correct |
19 |
Correct |
72 ms |
3180 KB |
Output is correct |
20 |
Correct |
92 ms |
3436 KB |
Output is correct |
21 |
Correct |
30 ms |
2924 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
20 ms |
1644 KB |
Output is correct |
24 |
Correct |
36 ms |
3180 KB |
Output is correct |
25 |
Correct |
5 ms |
620 KB |
Output is correct |
26 |
Correct |
23 ms |
2196 KB |
Output is correct |
27 |
Correct |
30 ms |
2540 KB |
Output is correct |
28 |
Correct |
38 ms |
3308 KB |
Output is correct |
29 |
Correct |
12 ms |
1388 KB |
Output is correct |
30 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
2816 KB |
Output is correct |
2 |
Correct |
9 ms |
1004 KB |
Output is correct |
3 |
Correct |
18 ms |
1900 KB |
Output is correct |
4 |
Correct |
19 ms |
1900 KB |
Output is correct |
5 |
Correct |
25 ms |
2412 KB |
Output is correct |
6 |
Correct |
16 ms |
1644 KB |
Output is correct |
7 |
Correct |
4 ms |
620 KB |
Output is correct |
8 |
Correct |
16 ms |
1644 KB |
Output is correct |
9 |
Correct |
41 ms |
3948 KB |
Output is correct |
10 |
Correct |
23 ms |
2284 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
36 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
35 ms |
364 KB |
Output is correct |
22 |
Correct |
34 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
11 ms |
1280 KB |
Output is correct |
27 |
Correct |
31 ms |
3052 KB |
Output is correct |
28 |
Correct |
39 ms |
3436 KB |
Output is correct |
29 |
Correct |
72 ms |
3180 KB |
Output is correct |
30 |
Correct |
92 ms |
3436 KB |
Output is correct |
31 |
Correct |
30 ms |
2924 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
20 ms |
1644 KB |
Output is correct |
34 |
Correct |
36 ms |
3180 KB |
Output is correct |
35 |
Correct |
5 ms |
620 KB |
Output is correct |
36 |
Correct |
23 ms |
2196 KB |
Output is correct |
37 |
Correct |
30 ms |
2540 KB |
Output is correct |
38 |
Correct |
38 ms |
3308 KB |
Output is correct |
39 |
Correct |
12 ms |
1388 KB |
Output is correct |
40 |
Correct |
2 ms |
364 KB |
Output is correct |
41 |
Correct |
71 ms |
3692 KB |
Output is correct |
42 |
Correct |
46 ms |
4076 KB |
Output is correct |
43 |
Correct |
54 ms |
3564 KB |
Output is correct |
44 |
Correct |
45 ms |
3948 KB |
Output is correct |
45 |
Correct |
44 ms |
4204 KB |
Output is correct |
46 |
Correct |
79 ms |
3948 KB |
Output is correct |
47 |
Correct |
38 ms |
3692 KB |
Output is correct |
48 |
Correct |
49 ms |
3820 KB |
Output is correct |
49 |
Correct |
43 ms |
3708 KB |
Output is correct |
50 |
Correct |
252 ms |
4076 KB |
Output is correct |
51 |
Correct |
277 ms |
4220 KB |
Output is correct |
52 |
Correct |
249 ms |
3948 KB |
Output is correct |
53 |
Correct |
270 ms |
4204 KB |
Output is correct |
54 |
Correct |
251 ms |
3948 KB |
Output is correct |
55 |
Correct |
277 ms |
4460 KB |
Output is correct |
56 |
Correct |
242 ms |
3692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
28 ms |
2816 KB |
Output is correct |
10 |
Correct |
9 ms |
1004 KB |
Output is correct |
11 |
Correct |
18 ms |
1900 KB |
Output is correct |
12 |
Correct |
19 ms |
1900 KB |
Output is correct |
13 |
Correct |
25 ms |
2412 KB |
Output is correct |
14 |
Correct |
16 ms |
1644 KB |
Output is correct |
15 |
Correct |
4 ms |
620 KB |
Output is correct |
16 |
Correct |
16 ms |
1644 KB |
Output is correct |
17 |
Correct |
41 ms |
3948 KB |
Output is correct |
18 |
Correct |
23 ms |
2284 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
36 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
35 ms |
364 KB |
Output is correct |
30 |
Correct |
34 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
11 ms |
1280 KB |
Output is correct |
35 |
Correct |
31 ms |
3052 KB |
Output is correct |
36 |
Correct |
39 ms |
3436 KB |
Output is correct |
37 |
Correct |
72 ms |
3180 KB |
Output is correct |
38 |
Correct |
92 ms |
3436 KB |
Output is correct |
39 |
Correct |
30 ms |
2924 KB |
Output is correct |
40 |
Correct |
1 ms |
364 KB |
Output is correct |
41 |
Correct |
20 ms |
1644 KB |
Output is correct |
42 |
Correct |
36 ms |
3180 KB |
Output is correct |
43 |
Correct |
5 ms |
620 KB |
Output is correct |
44 |
Correct |
23 ms |
2196 KB |
Output is correct |
45 |
Correct |
30 ms |
2540 KB |
Output is correct |
46 |
Correct |
38 ms |
3308 KB |
Output is correct |
47 |
Correct |
12 ms |
1388 KB |
Output is correct |
48 |
Correct |
2 ms |
364 KB |
Output is correct |
49 |
Correct |
71 ms |
3692 KB |
Output is correct |
50 |
Correct |
46 ms |
4076 KB |
Output is correct |
51 |
Correct |
54 ms |
3564 KB |
Output is correct |
52 |
Correct |
45 ms |
3948 KB |
Output is correct |
53 |
Correct |
44 ms |
4204 KB |
Output is correct |
54 |
Correct |
79 ms |
3948 KB |
Output is correct |
55 |
Correct |
38 ms |
3692 KB |
Output is correct |
56 |
Correct |
49 ms |
3820 KB |
Output is correct |
57 |
Correct |
43 ms |
3708 KB |
Output is correct |
58 |
Correct |
252 ms |
4076 KB |
Output is correct |
59 |
Correct |
277 ms |
4220 KB |
Output is correct |
60 |
Correct |
249 ms |
3948 KB |
Output is correct |
61 |
Correct |
270 ms |
4204 KB |
Output is correct |
62 |
Correct |
251 ms |
3948 KB |
Output is correct |
63 |
Correct |
277 ms |
4460 KB |
Output is correct |
64 |
Correct |
242 ms |
3692 KB |
Output is correct |
65 |
Correct |
1 ms |
364 KB |
Output is correct |
66 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
67 |
Halted |
0 ms |
0 KB |
- |