#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define vi vector<int>
#define ii pair<int,int>
#define iii tuple<int,int,int>
#define vii vector<ii>
#define viii vector<iii>
#define vb vector<bool>
#define pb push_back
#define eb emplace_back
const int maxn = 1e5+6;
const int inf = 1e18;
//010000
//100000
//001101
//001100
//000010
//000000
//
//00000
//00000
//00000
//00000
//00000
//
//what we need: number of painted black cells, number of cells, area of each square,
void solve() {
int n, k; cin >> n >> k;
if(!k){cout << n*n/2;exit(0);}
int cells = n*n, bcells = 0, blacks = 0;
vii top(k), bottom(k);
set<int> factors; vi divs;
for (int i = 0; i < k; i++) {
cin >> top[i].first >> top[i].second >> bottom[i].first >> bottom[i].second;
bcells += abs(top[i].first-bottom[i].first+1)*abs(top[i].second-bottom[i].second+1);
blacks += (top[i].first+top[i].second)&1;
} for (int i = 2; i*i<=n; i++) {
if (n%i==0) factors.insert(i), factors.insert(n/i);
} for (int i : factors) divs.eb(i);
int mn = min(bcells+cells/2-2*blacks,cells-cells/2-bcells+2*blacks);
for (int i = 0; i < divs.size(); i++) {
int side = divs[i];
int cntsq = n/side; // each
//mn=min(mn,min(x,y));
} cout << mn;// << ' ' << bcells << ' ' << blacks;
}
signed main() {
cin.tie()->sync_with_stdio(0);
int tc = 1;
//cin >> tc;
while (tc--) {
solve();
cout << '\n';
}
}
Compilation message
chessboard.cpp: In function 'void solve()':
chessboard.cpp:44:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for (int i = 0; i < divs.size(); i++) {
| ~~^~~~~~~~~~~~~
chessboard.cpp:46:13: warning: unused variable 'cntsq' [-Wunused-variable]
46 | int cntsq = n/side; // each
| ^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
452 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
3672 KB |
Output is correct |
2 |
Correct |
5 ms |
1116 KB |
Output is correct |
3 |
Correct |
11 ms |
2396 KB |
Output is correct |
4 |
Correct |
11 ms |
2652 KB |
Output is correct |
5 |
Correct |
14 ms |
3420 KB |
Output is correct |
6 |
Correct |
10 ms |
2140 KB |
Output is correct |
7 |
Correct |
3 ms |
724 KB |
Output is correct |
8 |
Correct |
9 ms |
2140 KB |
Output is correct |
9 |
Correct |
24 ms |
5196 KB |
Output is correct |
10 |
Correct |
13 ms |
3180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
3672 KB |
Output is correct |
2 |
Correct |
5 ms |
1116 KB |
Output is correct |
3 |
Correct |
11 ms |
2396 KB |
Output is correct |
4 |
Correct |
11 ms |
2652 KB |
Output is correct |
5 |
Correct |
14 ms |
3420 KB |
Output is correct |
6 |
Correct |
10 ms |
2140 KB |
Output is correct |
7 |
Correct |
3 ms |
724 KB |
Output is correct |
8 |
Correct |
9 ms |
2140 KB |
Output is correct |
9 |
Correct |
24 ms |
5196 KB |
Output is correct |
10 |
Correct |
13 ms |
3180 KB |
Output is correct |
11 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
452 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |