#include <iostream>
#include <cstdio>
using namespace std;
#define m_p make_pair
const int N = 100005;
struct ban
{
int x, y;
ban(){}
ban(int x, int y)
{
this->x = x;
this->y = y;
}
};
int n;
int m;
pair<ban, ban> a[N];
bool vv;
bool sevv(int x, int y, int t)
{
x = x / t;
y = y / t;
if ((x + y) % 2 == 0)
{
if (vv)
return true;
else
return false;
}
else
{
if (vv)
return false;
else
return true;
}
}
long long sev(const pair<ban, ban>& a, int t)
{
int x1 = a.first.x;
int y1 = a.first.y;
int x2 = a.second.x;
int y2 = a.second.y;
int xm1 = (x1 / t + 1) * t;
if (x1 % t == 0)
xm1 = x1;
int xm2 = (x2 / t) * t - 1;
if (x2 % t == t - 1)
xm2 = x2;
int ym1 = (y1 / t + 1) * t;
if (y1 % t == 0)
ym1 = y1;
int ym2 = (y2 / t) * t - 1;
if (y2 % t == t - 1)
ym2 = y2;
long long ans = 0;
// y1; ym1 - 1
// x1; xm1 - 1
long long xx = 0;
if (sevv(x1, y1, t))
xx += (xm1 - x1);
// xm1; xm2
if (!sevv(xm1, y1, t))
xx += ((((xm2 - xm1 + 1) / t) / 2) * t);
else
xx += ((((xm2 - xm1 + 1) / t) - (((xm2 - xm1 + 1) / t) / 2)) * t);
// xm2 + 1; x2
if (sevv(xm2 + 1, y1, t))
xx += (x2 - xm2);
if (xm1 - xm2 == t + 1)
{
xx = 0;
if (sevv(x1, y1, t))
xx = (x2 - x1 + 1);
}
ans += ((ym1 - y1) * xx);
// ym1; ym2
// x1; xm1 - 1
xx = 0;
if (sevv(x1, ym1, t))
xx += (xm1 - x1);
// xm1; xm2
if (!sevv(xm1, ym1, t))
xx += ((((xm2 - xm1 + 1) / t) / 2) * t);
else
xx += ((((xm2 - xm1 + 1) / t) - (((xm2 - xm1 + 1) / t) / 2)) * t);
// xm2 + 1; x2
if (sevv(xm2 + 1, ym1, t))
xx += (x2 - xm2);
if (xm1 - xm2 == t + 1)
{
xx = 0;
if (sevv(x1, ym1, t))
xx = (x2 - x1 + 1);
}
ans += ((((ym2 - ym1 + 1) / t) / 2) * ((x2 - x1 + 1) - xx) * t);
ans += ((((ym2 - ym1 + 1) / t) - (((ym2 - ym1 + 1) / t) / 2)) * xx * t);
// ym2 + 1; y2
// x1; xm1 - 1
xx = 0;
if (sevv(x1, ym2 + 1, t))
xx += (xm1 - x1);
// xm1; xm2
if (!sevv(xm1, ym2 + 1, t))
xx += ((((xm2 - xm1 + 1) / t) / 2) * t);
else
xx += ((((xm2 - xm1 + 1) / t) - (((xm2 - xm1 + 1) / t) / 2)) * t);
// xm2 + 1; x2
if (sevv(xm2 + 1, ym2 + 1, t))
xx += (x2 - xm2);
if (xm1 - xm2 == t + 1)
{
xx = 0;
if (sevv(x1, ym2 + 1, t))
xx = (x2 - x1 + 1);
}
ans += ((y2 - ym2) * xx);
if (ym1 - ym2 == t + 1)
{
ans = 0;
xx = 0;
if (sevv(x1, y1, t))
xx += (xm1 - x1);
// xm1; xm2
if (!sevv(xm1, y1, t))
xx += ((((xm2 - xm1 + 1) / t) / 2) * t);
else
xx += ((((xm2 - xm1 + 1) / t) - (((xm2 - xm1 + 1) / t) / 2)) * t);
// xm2 + 1; x2
if (sevv(xm2 + 1, y1, t))
xx += (x2 - xm2);
if (xm1 - xm2 == t + 1)
{
xx = 0;
if (sevv(x1, y1, t))
xx = (x2 - x1 + 1);
}
ans += (xx * (y2 - y1 + 1));
}
return ans;
}
long long spi(const pair<ban, ban>& a, int t)
{
int x1 = a.first.x;
int y1 = a.first.y;
int x2 = a.second.x;
int y2 = a.second.y;
return 1LL * (x2 - x1 + 1) * (y2 - y1 + 1) - sev(a, t);
}
long long ans;
void stg(int t)
{
vv = true;
long long yans = 0;
long long g = 0;
for (int i = 0; i < m; ++i)
{
long long spii = spi(a[i], t);
yans += (spii);
g += (1LL * (a[i].second.x - a[i].first.x + 1) * (a[i].second.y - a[i].first.y + 1) - spii);
}
yans += (sev(m_p(ban(0, 0), ban(n - 1, n - 1)), t) - g);
ans = min(ans, yans);
vv = false;
yans = 0;
g = 0;
for (int i = 0; i < m; ++i)
{
long long spii = spi(a[i], t);
yans += (spii);
g += (1LL * (a[i].second.x - a[i].first.x + 1) * (a[i].second.y - a[i].first.y + 1) - spii);
}
yans += (sev(m_p(ban(0, 0), ban(n - 1, n - 1)), t) - g);
ans = min(ans, yans);
}
int b[8][8];
int main()
{
/*vv = true;
for (int i = 0; i < 6; ++i)
{
for (int j = 0; j < 6; ++j)
{
if (sevv(i, j, 1))
b[i][j] = 1;
}
}
for (int x1 = 0; x1 < 6; ++x1)
{
for (int x2 = x1; x2 < 6; ++x2)
{
for (int y1 = 0; y1 < 6; ++y1)
{
for (int y2 = y1; y2 < 6; ++y2)
{
cout << x1 << ' ' << x2 << ' ' << y1 << ' ' << y2 << endl;
if (x1 == 4 && x2 == 4 && y1 == 0 && y2 == 4)
cout << "";
int ans1 = sev(m_p(ban(x1, y1), ban(x2, y2)), 1);
int ans2 = 0;
for (int i = x1; i <= x2; ++i)
{
for (int j = y1; j <= y2; ++j)
{
ans2 += b[i][j];
}
}
if (ans1 != ans2)
cout << "asdfdafjklshdfkjhaskjldfhakjl" << endl;
}
}
}
}*/
//freopen("input2.txt", "r", stdin);
scanf("%d%d", &n, &m);
for (int i = 0; i < m; ++i)
{
scanf("%d%d%d%d", &a[i].first.x, &a[i].first.y, &a[i].second.x, &a[i].second.y);
--a[i].first.x;
--a[i].first.y;
--a[i].second.x;
--a[i].second.y;
}
ans = 1LL * n * n;
for (int i = 1; i * i <= n; ++i)
{
if (n % i == 0)
{
if (i != n)
stg(i);
if (n / i != n)
stg(n / i);
}
}
cout << ans << endl;
return 0;
}
Compilation message
chessboard.cpp: In function 'int main()':
chessboard.cpp:230:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~
chessboard.cpp:233:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d", &a[i].first.x, &a[i].first.y, &a[i].second.x, &a[i].second.y);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
1344 KB |
Output is correct |
2 |
Correct |
9 ms |
504 KB |
Output is correct |
3 |
Correct |
22 ms |
888 KB |
Output is correct |
4 |
Correct |
23 ms |
1016 KB |
Output is correct |
5 |
Correct |
28 ms |
1144 KB |
Output is correct |
6 |
Correct |
19 ms |
836 KB |
Output is correct |
7 |
Correct |
6 ms |
504 KB |
Output is correct |
8 |
Correct |
19 ms |
892 KB |
Output is correct |
9 |
Correct |
47 ms |
1784 KB |
Output is correct |
10 |
Correct |
27 ms |
1144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
23 ms |
760 KB |
Output is correct |
17 |
Correct |
39 ms |
1628 KB |
Output is correct |
18 |
Correct |
77 ms |
1912 KB |
Output is correct |
19 |
Correct |
397 ms |
1744 KB |
Output is correct |
20 |
Correct |
457 ms |
1784 KB |
Output is correct |
21 |
Correct |
38 ms |
1528 KB |
Output is correct |
22 |
Correct |
3 ms |
380 KB |
Output is correct |
23 |
Correct |
60 ms |
1016 KB |
Output is correct |
24 |
Correct |
70 ms |
1784 KB |
Output is correct |
25 |
Correct |
13 ms |
504 KB |
Output is correct |
26 |
Correct |
45 ms |
1272 KB |
Output is correct |
27 |
Correct |
76 ms |
1400 KB |
Output is correct |
28 |
Correct |
73 ms |
1784 KB |
Output is correct |
29 |
Correct |
17 ms |
888 KB |
Output is correct |
30 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
1344 KB |
Output is correct |
2 |
Correct |
9 ms |
504 KB |
Output is correct |
3 |
Correct |
22 ms |
888 KB |
Output is correct |
4 |
Correct |
23 ms |
1016 KB |
Output is correct |
5 |
Correct |
28 ms |
1144 KB |
Output is correct |
6 |
Correct |
19 ms |
836 KB |
Output is correct |
7 |
Correct |
6 ms |
504 KB |
Output is correct |
8 |
Correct |
19 ms |
892 KB |
Output is correct |
9 |
Correct |
47 ms |
1784 KB |
Output is correct |
10 |
Correct |
27 ms |
1144 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
3 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
256 KB |
Output is correct |
23 |
Correct |
3 ms |
376 KB |
Output is correct |
24 |
Correct |
3 ms |
376 KB |
Output is correct |
25 |
Correct |
3 ms |
376 KB |
Output is correct |
26 |
Correct |
23 ms |
760 KB |
Output is correct |
27 |
Correct |
39 ms |
1628 KB |
Output is correct |
28 |
Correct |
77 ms |
1912 KB |
Output is correct |
29 |
Correct |
397 ms |
1744 KB |
Output is correct |
30 |
Correct |
457 ms |
1784 KB |
Output is correct |
31 |
Correct |
38 ms |
1528 KB |
Output is correct |
32 |
Correct |
3 ms |
380 KB |
Output is correct |
33 |
Correct |
60 ms |
1016 KB |
Output is correct |
34 |
Correct |
70 ms |
1784 KB |
Output is correct |
35 |
Correct |
13 ms |
504 KB |
Output is correct |
36 |
Correct |
45 ms |
1272 KB |
Output is correct |
37 |
Correct |
76 ms |
1400 KB |
Output is correct |
38 |
Correct |
73 ms |
1784 KB |
Output is correct |
39 |
Correct |
17 ms |
888 KB |
Output is correct |
40 |
Correct |
4 ms |
376 KB |
Output is correct |
41 |
Correct |
320 ms |
1660 KB |
Output is correct |
42 |
Correct |
78 ms |
1784 KB |
Output is correct |
43 |
Correct |
176 ms |
1656 KB |
Output is correct |
44 |
Correct |
79 ms |
1784 KB |
Output is correct |
45 |
Correct |
52 ms |
1912 KB |
Output is correct |
46 |
Correct |
354 ms |
1840 KB |
Output is correct |
47 |
Correct |
45 ms |
1656 KB |
Output is correct |
48 |
Correct |
126 ms |
1656 KB |
Output is correct |
49 |
Correct |
69 ms |
1784 KB |
Output is correct |
50 |
Correct |
1773 ms |
1780 KB |
Output is correct |
51 |
Correct |
1890 ms |
4192 KB |
Output is correct |
52 |
Correct |
1769 ms |
3960 KB |
Output is correct |
53 |
Correct |
1871 ms |
4188 KB |
Output is correct |
54 |
Correct |
1729 ms |
3960 KB |
Output is correct |
55 |
Correct |
1925 ms |
4332 KB |
Output is correct |
56 |
Correct |
1745 ms |
3704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
32 ms |
1344 KB |
Output is correct |
10 |
Correct |
9 ms |
504 KB |
Output is correct |
11 |
Correct |
22 ms |
888 KB |
Output is correct |
12 |
Correct |
23 ms |
1016 KB |
Output is correct |
13 |
Correct |
28 ms |
1144 KB |
Output is correct |
14 |
Correct |
19 ms |
836 KB |
Output is correct |
15 |
Correct |
6 ms |
504 KB |
Output is correct |
16 |
Correct |
19 ms |
892 KB |
Output is correct |
17 |
Correct |
47 ms |
1784 KB |
Output is correct |
18 |
Correct |
27 ms |
1144 KB |
Output is correct |
19 |
Correct |
2 ms |
256 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
3 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
256 KB |
Output is correct |
31 |
Correct |
3 ms |
376 KB |
Output is correct |
32 |
Correct |
3 ms |
376 KB |
Output is correct |
33 |
Correct |
3 ms |
376 KB |
Output is correct |
34 |
Correct |
23 ms |
760 KB |
Output is correct |
35 |
Correct |
39 ms |
1628 KB |
Output is correct |
36 |
Correct |
77 ms |
1912 KB |
Output is correct |
37 |
Correct |
397 ms |
1744 KB |
Output is correct |
38 |
Correct |
457 ms |
1784 KB |
Output is correct |
39 |
Correct |
38 ms |
1528 KB |
Output is correct |
40 |
Correct |
3 ms |
380 KB |
Output is correct |
41 |
Correct |
60 ms |
1016 KB |
Output is correct |
42 |
Correct |
70 ms |
1784 KB |
Output is correct |
43 |
Correct |
13 ms |
504 KB |
Output is correct |
44 |
Correct |
45 ms |
1272 KB |
Output is correct |
45 |
Correct |
76 ms |
1400 KB |
Output is correct |
46 |
Correct |
73 ms |
1784 KB |
Output is correct |
47 |
Correct |
17 ms |
888 KB |
Output is correct |
48 |
Correct |
4 ms |
376 KB |
Output is correct |
49 |
Correct |
320 ms |
1660 KB |
Output is correct |
50 |
Correct |
78 ms |
1784 KB |
Output is correct |
51 |
Correct |
176 ms |
1656 KB |
Output is correct |
52 |
Correct |
79 ms |
1784 KB |
Output is correct |
53 |
Correct |
52 ms |
1912 KB |
Output is correct |
54 |
Correct |
354 ms |
1840 KB |
Output is correct |
55 |
Correct |
45 ms |
1656 KB |
Output is correct |
56 |
Correct |
126 ms |
1656 KB |
Output is correct |
57 |
Correct |
69 ms |
1784 KB |
Output is correct |
58 |
Correct |
1773 ms |
1780 KB |
Output is correct |
59 |
Correct |
1890 ms |
4192 KB |
Output is correct |
60 |
Correct |
1769 ms |
3960 KB |
Output is correct |
61 |
Correct |
1871 ms |
4188 KB |
Output is correct |
62 |
Correct |
1729 ms |
3960 KB |
Output is correct |
63 |
Correct |
1925 ms |
4332 KB |
Output is correct |
64 |
Correct |
1745 ms |
3704 KB |
Output is correct |
65 |
Correct |
2 ms |
376 KB |
Output is correct |
66 |
Correct |
2 ms |
256 KB |
Output is correct |
67 |
Correct |
1878 ms |
4032 KB |
Output is correct |
68 |
Correct |
1854 ms |
4084 KB |
Output is correct |
69 |
Correct |
1611 ms |
3708 KB |
Output is correct |
70 |
Correct |
1769 ms |
4060 KB |
Output is correct |
71 |
Correct |
1746 ms |
3884 KB |
Output is correct |
72 |
Correct |
1740 ms |
3848 KB |
Output is correct |
73 |
Correct |
1695 ms |
3704 KB |
Output is correct |
74 |
Correct |
1883 ms |
4088 KB |
Output is correct |
75 |
Correct |
1762 ms |
3960 KB |
Output is correct |
76 |
Correct |
1915 ms |
4088 KB |
Output is correct |
77 |
Correct |
269 ms |
4344 KB |
Output is correct |
78 |
Correct |
78 ms |
3832 KB |
Output is correct |
79 |
Correct |
188 ms |
3704 KB |
Output is correct |
80 |
Correct |
194 ms |
3832 KB |
Output is correct |
81 |
Correct |
177 ms |
3576 KB |
Output is correct |
82 |
Correct |
143 ms |
4104 KB |
Output is correct |
83 |
Correct |
108 ms |
3832 KB |
Output is correct |
84 |
Correct |
1101 ms |
4316 KB |
Output is correct |
85 |
Correct |
1996 ms |
4216 KB |
Output is correct |
86 |
Correct |
3 ms |
256 KB |
Output is correct |
87 |
Correct |
2 ms |
376 KB |
Output is correct |
88 |
Correct |
1990 ms |
4344 KB |
Output is correct |
89 |
Correct |
377 ms |
1144 KB |
Output is correct |
90 |
Correct |
2 ms |
256 KB |
Output is correct |