#include <bits/stdc++.h>
#define int long long
using namespace std;
/*************************************
*
* Without Subtask 4 : 70 points
*
*/
struct point
{
int x1, y1, x2, y2;
};
signed main()
{
int n, m, k, ans = 1000000000;
cin >> n >> k;
vector<point> v(k);
vector<int> fac;
for (int i = 0; i < k; i++)
cin >> v[i].x1 >> v[i].y1 >> v[i].x2 >> v[i].y2;
for (int i = 1; i <= sqrt(n); i++)
{
fac.emplace_back(i);
if(i * i != n && i != 1)
fac.emplace_back(n / i);
}
for (int i : fac)
if (n % i == 0)
{
int l = 0, r = 0;
for (auto j : v)
if (((j.x1 + i - 1) / i + (j.y1 + i - 1) / i) % 2)
r++;
else
l++;
//cout << i << " " << min({(n * n - i * i + 1) / 2 - l + r, (n * n - i * i) / 2 + l - r}) << '\n';
if ((n / i) % 2)
ans = min({ans, (n * n - i * i) / 2 + i * i - l + r, (n * n - i * i) / 2 + l - r});
else
ans = min({ans, (n * n) / 2 - l + r, (n * n) / 2 + l - r});
}
cout << ans << '\n';
}
Compilation message
chessboard.cpp: In function 'int main()':
chessboard.cpp:18:12: warning: unused variable 'm' [-Wunused-variable]
18 | int n, m, k, ans = 1000000000;
| ^
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
74 ms |
2332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 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 |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 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 |
364 KB |
Output is correct |
16 |
Correct |
27 ms |
1132 KB |
Output is correct |
17 |
Correct |
79 ms |
2944 KB |
Output is correct |
18 |
Correct |
96 ms |
3448 KB |
Output is correct |
19 |
Correct |
119 ms |
3052 KB |
Output is correct |
20 |
Correct |
137 ms |
3460 KB |
Output is correct |
21 |
Correct |
77 ms |
2796 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
44 ms |
1644 KB |
Output is correct |
24 |
Correct |
92 ms |
3308 KB |
Output is correct |
25 |
Correct |
9 ms |
620 KB |
Output is correct |
26 |
Correct |
57 ms |
2028 KB |
Output is correct |
27 |
Correct |
69 ms |
2412 KB |
Output is correct |
28 |
Correct |
92 ms |
3308 KB |
Output is correct |
29 |
Correct |
32 ms |
1388 KB |
Output is correct |
30 |
Correct |
3 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
74 ms |
2332 KB |
Output isn't correct |
2 |
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 |
0 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 |
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 |
Incorrect |
74 ms |
2332 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |