#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
const int INF = 1e9 + 7;
const ll oo = 1e18;
signed main()
{
IO_OP;
int n, k;
cin >> n >> k;
V<array<int, 4>> a(k);
for(int i = 0; i < k; i++) {
for(int j = 0; j < 4; j++)
cin >> a[i][j], a[i][j]--;
}
ll ans = oo;
auto go = [&] (int b) {
int m = n / b;
ll white = (ll) m * m / 2 * b * b, black = (ll) n * n - white;
ll wb = 0;
auto solve = [&] (int x, int y) {
if(x < 0 || y < 0) return 0LL;
int l = (x + 1) % (2 * b), r = (y + 1) % (2 * b);
ll W = 0, B = 0;
B += (ll) min(l, b) * min(r, b);
B += (ll) max(0, l - b) * max(0, r - b);
W += (ll) min(l, b) * max(0, r - b);;
W += (ll) max(0, l - b) * min(r, r - b);
if((x / (2 * b) * (2 * b) / b + y / (2 * b) * (2 * b) / b) % 2) swap(W, B);
return W - B;
};
for(int i = 0; i < k; i++) {
wb += solve(a[i][2], a[i][3]) - solve(a[i][0] - 1, a[i][3]) - solve(a[i][2], a[i][1] - 1) + solve(a[i][0] - 1, a[i][1] - 1);
}
return black + wb;
};
for(int i = 1; i < n; i++) {
if(n % i == 0) {
ll t = go(i);
t = min(t, (ll) n * n - t);
ans = min(ans, t);
}
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 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 |
364 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 |
396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
1260 KB |
Output is correct |
2 |
Correct |
9 ms |
620 KB |
Output is correct |
3 |
Correct |
22 ms |
1004 KB |
Output is correct |
4 |
Correct |
24 ms |
1004 KB |
Output is correct |
5 |
Correct |
31 ms |
1132 KB |
Output is correct |
6 |
Correct |
20 ms |
876 KB |
Output is correct |
7 |
Correct |
5 ms |
492 KB |
Output is correct |
8 |
Correct |
24 ms |
876 KB |
Output is correct |
9 |
Correct |
54 ms |
1792 KB |
Output is correct |
10 |
Correct |
28 ms |
1132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
1260 KB |
Output is correct |
2 |
Correct |
9 ms |
620 KB |
Output is correct |
3 |
Correct |
22 ms |
1004 KB |
Output is correct |
4 |
Correct |
24 ms |
1004 KB |
Output is correct |
5 |
Correct |
31 ms |
1132 KB |
Output is correct |
6 |
Correct |
20 ms |
876 KB |
Output is correct |
7 |
Correct |
5 ms |
492 KB |
Output is correct |
8 |
Correct |
24 ms |
876 KB |
Output is correct |
9 |
Correct |
54 ms |
1792 KB |
Output is correct |
10 |
Correct |
28 ms |
1132 KB |
Output is correct |
11 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 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 |
364 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 |
396 KB |
Output is correct |
9 |
Correct |
36 ms |
1260 KB |
Output is correct |
10 |
Correct |
9 ms |
620 KB |
Output is correct |
11 |
Correct |
22 ms |
1004 KB |
Output is correct |
12 |
Correct |
24 ms |
1004 KB |
Output is correct |
13 |
Correct |
31 ms |
1132 KB |
Output is correct |
14 |
Correct |
20 ms |
876 KB |
Output is correct |
15 |
Correct |
5 ms |
492 KB |
Output is correct |
16 |
Correct |
24 ms |
876 KB |
Output is correct |
17 |
Correct |
54 ms |
1792 KB |
Output is correct |
18 |
Correct |
28 ms |
1132 KB |
Output is correct |
19 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |