This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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
| ^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |