#include <bits/stdc++.h>
# define pb push_back
# define ff first
# define ss second
# define nl "\n"
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll maxn = 1e5 + 25;
const ll maxl = 22 + 0;
const ll inf = 2e9 + 0;
const ll mod = 998244353;
const ll dx[] = {-1, 1, 0, 0};
const ll dy[] = {0, 0, -1, 1};
using namespace std;
ll n, k;
struct rect
{
ll x1, y1, x2, y2;
} q[maxn];
ll pref[1007][1007];
ll get (ll x1, ll y1, ll x2, ll y2)
{
return pref[x2][y2] - pref[x1 - 1][y2] - pref[x2][y1 - 1] + pref[x1 - 1][y1 - 1];
}
bool prime (ll x)
{
for (ll i = 2; i * i <= x; ++i)
{
if (x % i == 0) return 0;
if (x % (x / i) == 0) return 0;
}
return 1;
}
ll solve1 (ll len)
{
ll res1 = 0, res2 = 0;;
ll cnt = 0;
for (ll i = 1; i <= n; i += len)
{
if (cnt % 2 == 0)
{
bool boo = 1;
for (ll j = 1; j <= n; j += len)
{
if (boo)
{
res1 += (len * len) - get(i, j, i + len - 1, j + len - 1);
res2 += get(i, j, i + len - 1, j + len - 1);
}
else
{
res1 += get(i, j, i + len - 1, j + len - 1);
res2 += (len * len) - get(i, j, i + len - 1, j + len - 1);
}
boo ^= 1;
}
}
else
{
bool boo = 1;
for (ll j = 1; j <= n; j += len)
{
if (boo)
{
res1 += get(i, j, i + len - 1, j + len - 1);
res2 += (len * len) - get(i, j, i + len - 1, j + len - 1);
}
else
{
res1 += (len * len) - get(i, j, i + len - 1, j + len - 1);
res2 += get(i, j, i + len - 1, j + len - 1);
}
boo ^= 1;
}
}
cnt++;
}
return min(res1, res2);
}
void ma1n ()
{
cin >> n >> k;
for (ll i = 1; i <= k; ++i)
{
cin >> q[i].x1 >> q[i].y1 >> q[i].x2 >> q[i].y2;
}
if (prime(n))
{
ll cnt0 = 0, cnt1 = 0;
for (ll i = 1; i <= k; ++i)
{
if ((q[i].x1 + q[i].y1) & 1) cnt1++;
else cnt0++;
}
ll ans1 = ((((n + 1) / 2) * ((n + 1) / 2)) + ((n / 2) * (n / 2))) - cnt0 + cnt1;
ll ans2 = ((((n + 1) / 2) * (n / 2)) + (((n + 1) / 2) * (n / 2))) - cnt1 + cnt0;
cout << min(ans1, ans2) << nl;
}
else if (n <= 1000)
{
for (ll i = 1; i <= k; ++i)
{
pref[q[i].x1][q[i].y1]++;
}
for (ll i = 1; i <= n; ++i)
{
for (ll j = 1; j <= n; ++j)
{
pref[i][j] += pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1];
}
}
ll ans = n * n;
for (ll len = 1; len < n; ++len)
{
if (n % len == 0)
{
ans = min(ans, solve1(len));
}
}
cout << ans << nl;
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
// freopen("mooyomooyo.in", "r", stdin);
// freopen("mooyomooyo.out", "w", stdout);
int ttt = 1;
// cin >> ttt;
for (int test = 1; test <= ttt; ++test)
{
// cout << "Case " << test << ":" << nl;
ma1n();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
2260 KB |
Output is correct |
2 |
Correct |
6 ms |
792 KB |
Output is correct |
3 |
Correct |
11 ms |
1488 KB |
Output is correct |
4 |
Correct |
12 ms |
1772 KB |
Output is correct |
5 |
Correct |
15 ms |
2004 KB |
Output is correct |
6 |
Correct |
14 ms |
1384 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
13 ms |
1380 KB |
Output is correct |
9 |
Correct |
33 ms |
3152 KB |
Output is correct |
10 |
Correct |
16 ms |
1832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
724 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
724 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
15 ms |
8688 KB |
Output is correct |
17 |
Correct |
21 ms |
4300 KB |
Output is correct |
18 |
Correct |
33 ms |
12748 KB |
Output is correct |
19 |
Correct |
41 ms |
11996 KB |
Output is correct |
20 |
Correct |
35 ms |
12536 KB |
Output is correct |
21 |
Correct |
21 ms |
4088 KB |
Output is correct |
22 |
Correct |
9 ms |
8148 KB |
Output is correct |
23 |
Correct |
18 ms |
9940 KB |
Output is correct |
24 |
Correct |
40 ms |
12364 KB |
Output is correct |
25 |
Correct |
9 ms |
8356 KB |
Output is correct |
26 |
Correct |
23 ms |
10492 KB |
Output is correct |
27 |
Correct |
25 ms |
11136 KB |
Output is correct |
28 |
Correct |
31 ms |
12408 KB |
Output is correct |
29 |
Correct |
9 ms |
1872 KB |
Output is correct |
30 |
Correct |
8 ms |
8148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
2260 KB |
Output is correct |
2 |
Correct |
6 ms |
792 KB |
Output is correct |
3 |
Correct |
11 ms |
1488 KB |
Output is correct |
4 |
Correct |
12 ms |
1772 KB |
Output is correct |
5 |
Correct |
15 ms |
2004 KB |
Output is correct |
6 |
Correct |
14 ms |
1384 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
13 ms |
1380 KB |
Output is correct |
9 |
Correct |
33 ms |
3152 KB |
Output is correct |
10 |
Correct |
16 ms |
1832 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
724 KB |
Output is correct |
15 |
Correct |
1 ms |
724 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
724 KB |
Output is correct |
18 |
Correct |
1 ms |
596 KB |
Output is correct |
19 |
Correct |
1 ms |
724 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
596 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
596 KB |
Output is correct |
24 |
Correct |
1 ms |
724 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
15 ms |
8688 KB |
Output is correct |
27 |
Correct |
21 ms |
4300 KB |
Output is correct |
28 |
Correct |
33 ms |
12748 KB |
Output is correct |
29 |
Correct |
41 ms |
11996 KB |
Output is correct |
30 |
Correct |
35 ms |
12536 KB |
Output is correct |
31 |
Correct |
21 ms |
4088 KB |
Output is correct |
32 |
Correct |
9 ms |
8148 KB |
Output is correct |
33 |
Correct |
18 ms |
9940 KB |
Output is correct |
34 |
Correct |
40 ms |
12364 KB |
Output is correct |
35 |
Correct |
9 ms |
8356 KB |
Output is correct |
36 |
Correct |
23 ms |
10492 KB |
Output is correct |
37 |
Correct |
25 ms |
11136 KB |
Output is correct |
38 |
Correct |
31 ms |
12408 KB |
Output is correct |
39 |
Correct |
9 ms |
1872 KB |
Output is correct |
40 |
Correct |
8 ms |
8148 KB |
Output is correct |
41 |
Incorrect |
26 ms |
4808 KB |
Output isn't correct |
42 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
25 ms |
2260 KB |
Output is correct |
10 |
Correct |
6 ms |
792 KB |
Output is correct |
11 |
Correct |
11 ms |
1488 KB |
Output is correct |
12 |
Correct |
12 ms |
1772 KB |
Output is correct |
13 |
Correct |
15 ms |
2004 KB |
Output is correct |
14 |
Correct |
14 ms |
1384 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
13 ms |
1380 KB |
Output is correct |
17 |
Correct |
33 ms |
3152 KB |
Output is correct |
18 |
Correct |
16 ms |
1832 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
21 |
Correct |
1 ms |
596 KB |
Output is correct |
22 |
Correct |
1 ms |
724 KB |
Output is correct |
23 |
Correct |
1 ms |
724 KB |
Output is correct |
24 |
Correct |
1 ms |
596 KB |
Output is correct |
25 |
Correct |
1 ms |
724 KB |
Output is correct |
26 |
Correct |
1 ms |
596 KB |
Output is correct |
27 |
Correct |
1 ms |
724 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
596 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
596 KB |
Output is correct |
32 |
Correct |
1 ms |
724 KB |
Output is correct |
33 |
Correct |
1 ms |
468 KB |
Output is correct |
34 |
Correct |
15 ms |
8688 KB |
Output is correct |
35 |
Correct |
21 ms |
4300 KB |
Output is correct |
36 |
Correct |
33 ms |
12748 KB |
Output is correct |
37 |
Correct |
41 ms |
11996 KB |
Output is correct |
38 |
Correct |
35 ms |
12536 KB |
Output is correct |
39 |
Correct |
21 ms |
4088 KB |
Output is correct |
40 |
Correct |
9 ms |
8148 KB |
Output is correct |
41 |
Correct |
18 ms |
9940 KB |
Output is correct |
42 |
Correct |
40 ms |
12364 KB |
Output is correct |
43 |
Correct |
9 ms |
8356 KB |
Output is correct |
44 |
Correct |
23 ms |
10492 KB |
Output is correct |
45 |
Correct |
25 ms |
11136 KB |
Output is correct |
46 |
Correct |
31 ms |
12408 KB |
Output is correct |
47 |
Correct |
9 ms |
1872 KB |
Output is correct |
48 |
Correct |
8 ms |
8148 KB |
Output is correct |
49 |
Incorrect |
26 ms |
4808 KB |
Output isn't correct |
50 |
Halted |
0 ms |
0 KB |
- |