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>
#define pb push_back
#define sz(v) (int)v.size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define x first
#define y second
#define int long long
#define nl "\n"
using namespace std;
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair <ll, ll> pii;
const int N = (int)3e5 + 7;
const int M = (int)7e6 + 7;
const ll MOD = (ll)1e9 + 7;
const int inf = (int)1e9 + 7;
const ll INF = (ll)3e18 + 7;
pii dir[] = {{-1, -1}, {1, 1}, {-1, 1}, {1, -1}};
int n, k;
bool c[1001][1001];
int f(int x, bool cur) {
int ans = 0;
for(int i = 1; i <= n; i += x) {
bool ok = cur;
for(int j = 1; j <= n; j += x) {
int k = j + x - 1, t = i + x - 1;
for(int l = i; l <= t; ++l) {
for(int r = j; r <= k; ++r) {
if(ok) ans += (c[l][r] == 0);
else ans += (c[l][r] == 1);
}
}
ok ^= 1;
}
cur ^= 1;
}
return ans;
}
void solve() {
cin >> n >> k;
int ans = INF;
vector<pii> v;
vector<int> di;
for(int i = 1; i < n; ++i) {
if(n % i == 0) {
di.pb(i);
int x = n / i;
int a = (x * x) / 2, b = ((x / 2) * (x / 2)) + (((x + 1) / 2) * ((x + 1) / 2));
v.pb({a * i * i, b * i * i});
}
}
while(k--) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
for(int i = 0; i < sz(di); ++i) {
int pos = (x1 + di[i] - 1) / di[i];
int sop = (y1 + di[i] - 1) / di[i];
if(pos & 1) {
if(sop & 1) v[i].x++, v[i].y--;
else v[i].x--, v[i].y++;
} else {
if(sop & 1) v[i].x--, v[i].y++;
else v[i].x++, v[i].y--;
}
}
}
for(auto [x, y] : v) ans = min(ans, min(x, y));
cout << ans << nl;
}
signed main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0);
cout.tie(0);
int test = 1;
//cin >> test;
for(int i = 1; i <= test; ++i) {
//cout << "Case " << i << ": ";
solve();
}
return 0;
}
/*
6 8
3 3 3 3
1 2 1 2
3 4 3 4
5 5 5 5
4 3 4 3
4 4 4 4
2 1 2 1
3 6 3 6
*/
Compilation message (stderr)
chessboard.cpp: In function 'void solve()':
chessboard.cpp:76:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
76 | for(auto [x, y] : v) ans = min(ans, min(x, y));
| ^
# | 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... |