#include <bits/stdc++.h>
using namespace std;
#define pb push_back
long long n, k;
long long ans = LLONG_MAX;
struct square
{
int x, y;
};
vector <square> squares;
void solve(int squareSize)
{
long long idk = (n / squareSize), idk2;
// cout << squareSize << "\n";
if(idk % 2)
idk2 = idk * (idk / 2) + (idk + 1) / 2;
else
idk2 = idk * idk / 2;
// cout << idk << "\n";
long long cnt1 = 1ll * squareSize * squareSize * idk2, cnt2 = 1ll * n * n - cnt1;
// cout << cnt1 << " " << cnt2 << "\n";
for(auto x : squares)
{
long long r1, c1, r2, c2, a, b;
c1 = x.x / squareSize;
r1 = x.x % squareSize;
if(r1)
c1 ++;
a = c1 % 2;
c2 = x.y / squareSize;
r2 = x.y % squareSize;
if(r2)
c2 ++;
b = c2 % 2;
/// incepem cu alb
if(a == 1 && b == 0)
{
// cout << x.x << " " << x.y << "patrat negru\n";
cnt2 --;
}
else if(a == 1 && b == 1)
{
// cout << x.x << " " << x.y << "patrat alb\n";
// patrat alb
cnt2 ++;
}
else if(a == 0 && b == 0)
{
// cout << x.x << " " << x.y << "patrat alb\n";
// patrat alb
cnt2 ++;
}
else
{
// cout << x.x << " " << x.y << "patrat negru\n";
// patrat negru
cnt2 --;
}
/// acum negru
if(a == 1 && b == 0)
{
// cout << x.x << " " << x.y << "patrat alb\n";
// patrat alb
cnt1 ++;
}
else if(a == 1 && b == 1)
{
// cout << x.x << " " << x.y << "patrat negru\n";
// patrat negru
cnt1 --;
}
else if(a == 0 && b == 0)
{
// cout << x.x << " " << x.y << "patrat negru\n";
// patrat negru
cnt1 --;
}
else
{
// cout << x.x << " " << x.y << "patrat alb\n";
// patrat alb
cnt1 ++;
}
}
ans = min(ans, min(cnt1, cnt2));
// cout << cnt1 << " " << cnt2 << "\n\n";
}
int main()
{
ios_base :: sync_with_stdio(0);
cin.tie(0);
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
cin >> n >> k;
for(int i = 1; i <= k; i ++)
{
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
squares.pb({x1, y1});
}
long long d = 1;
while(d * d <= n)
{
if(n % d == 0)
{
solve(d);
if(d != 1 && d * d != n)
solve(n / d);
}
d ++;
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
856 KB |
Output is correct |
2 |
Correct |
4 ms |
596 KB |
Output is correct |
3 |
Correct |
11 ms |
880 KB |
Output is correct |
4 |
Correct |
12 ms |
856 KB |
Output is correct |
5 |
Correct |
14 ms |
956 KB |
Output is correct |
6 |
Correct |
9 ms |
856 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
10 ms |
984 KB |
Output is correct |
9 |
Correct |
22 ms |
1492 KB |
Output is correct |
10 |
Correct |
13 ms |
856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
7 ms |
600 KB |
Output is correct |
17 |
Correct |
18 ms |
1456 KB |
Output is correct |
18 |
Correct |
24 ms |
1420 KB |
Output is correct |
19 |
Correct |
57 ms |
1492 KB |
Output is correct |
20 |
Correct |
63 ms |
1464 KB |
Output is correct |
21 |
Correct |
18 ms |
1424 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
13 ms |
984 KB |
Output is correct |
24 |
Correct |
22 ms |
1484 KB |
Output is correct |
25 |
Correct |
3 ms |
468 KB |
Output is correct |
26 |
Correct |
14 ms |
984 KB |
Output is correct |
27 |
Correct |
19 ms |
1440 KB |
Output is correct |
28 |
Correct |
23 ms |
1460 KB |
Output is correct |
29 |
Correct |
8 ms |
856 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
856 KB |
Output is correct |
2 |
Correct |
4 ms |
596 KB |
Output is correct |
3 |
Correct |
11 ms |
880 KB |
Output is correct |
4 |
Correct |
12 ms |
856 KB |
Output is correct |
5 |
Correct |
14 ms |
956 KB |
Output is correct |
6 |
Correct |
9 ms |
856 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
10 ms |
984 KB |
Output is correct |
9 |
Correct |
22 ms |
1492 KB |
Output is correct |
10 |
Correct |
13 ms |
856 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
7 ms |
600 KB |
Output is correct |
27 |
Correct |
18 ms |
1456 KB |
Output is correct |
28 |
Correct |
24 ms |
1420 KB |
Output is correct |
29 |
Correct |
57 ms |
1492 KB |
Output is correct |
30 |
Correct |
63 ms |
1464 KB |
Output is correct |
31 |
Correct |
18 ms |
1424 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
13 ms |
984 KB |
Output is correct |
34 |
Correct |
22 ms |
1484 KB |
Output is correct |
35 |
Correct |
3 ms |
468 KB |
Output is correct |
36 |
Correct |
14 ms |
984 KB |
Output is correct |
37 |
Correct |
19 ms |
1440 KB |
Output is correct |
38 |
Correct |
23 ms |
1460 KB |
Output is correct |
39 |
Correct |
8 ms |
856 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
53 ms |
1492 KB |
Output is correct |
42 |
Correct |
26 ms |
1492 KB |
Output is correct |
43 |
Correct |
35 ms |
1492 KB |
Output is correct |
44 |
Correct |
26 ms |
1472 KB |
Output is correct |
45 |
Correct |
26 ms |
1500 KB |
Output is correct |
46 |
Correct |
59 ms |
1492 KB |
Output is correct |
47 |
Correct |
21 ms |
1464 KB |
Output is correct |
48 |
Correct |
31 ms |
1480 KB |
Output is correct |
49 |
Correct |
24 ms |
1404 KB |
Output is correct |
50 |
Correct |
226 ms |
1380 KB |
Output is correct |
51 |
Correct |
241 ms |
1412 KB |
Output is correct |
52 |
Correct |
224 ms |
1428 KB |
Output is correct |
53 |
Correct |
239 ms |
1492 KB |
Output is correct |
54 |
Correct |
221 ms |
1364 KB |
Output is correct |
55 |
Correct |
249 ms |
1492 KB |
Output is correct |
56 |
Correct |
214 ms |
1404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
16 ms |
856 KB |
Output is correct |
10 |
Correct |
4 ms |
596 KB |
Output is correct |
11 |
Correct |
11 ms |
880 KB |
Output is correct |
12 |
Correct |
12 ms |
856 KB |
Output is correct |
13 |
Correct |
14 ms |
956 KB |
Output is correct |
14 |
Correct |
9 ms |
856 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
10 ms |
984 KB |
Output is correct |
17 |
Correct |
22 ms |
1492 KB |
Output is correct |
18 |
Correct |
13 ms |
856 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
7 ms |
600 KB |
Output is correct |
35 |
Correct |
18 ms |
1456 KB |
Output is correct |
36 |
Correct |
24 ms |
1420 KB |
Output is correct |
37 |
Correct |
57 ms |
1492 KB |
Output is correct |
38 |
Correct |
63 ms |
1464 KB |
Output is correct |
39 |
Correct |
18 ms |
1424 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
13 ms |
984 KB |
Output is correct |
42 |
Correct |
22 ms |
1484 KB |
Output is correct |
43 |
Correct |
3 ms |
468 KB |
Output is correct |
44 |
Correct |
14 ms |
984 KB |
Output is correct |
45 |
Correct |
19 ms |
1440 KB |
Output is correct |
46 |
Correct |
23 ms |
1460 KB |
Output is correct |
47 |
Correct |
8 ms |
856 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
53 ms |
1492 KB |
Output is correct |
50 |
Correct |
26 ms |
1492 KB |
Output is correct |
51 |
Correct |
35 ms |
1492 KB |
Output is correct |
52 |
Correct |
26 ms |
1472 KB |
Output is correct |
53 |
Correct |
26 ms |
1500 KB |
Output is correct |
54 |
Correct |
59 ms |
1492 KB |
Output is correct |
55 |
Correct |
21 ms |
1464 KB |
Output is correct |
56 |
Correct |
31 ms |
1480 KB |
Output is correct |
57 |
Correct |
24 ms |
1404 KB |
Output is correct |
58 |
Correct |
226 ms |
1380 KB |
Output is correct |
59 |
Correct |
241 ms |
1412 KB |
Output is correct |
60 |
Correct |
224 ms |
1428 KB |
Output is correct |
61 |
Correct |
239 ms |
1492 KB |
Output is correct |
62 |
Correct |
221 ms |
1364 KB |
Output is correct |
63 |
Correct |
249 ms |
1492 KB |
Output is correct |
64 |
Correct |
214 ms |
1404 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
67 |
Halted |
0 ms |
0 KB |
- |