이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
#define pb emplace_back
#define y1 y_1
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }
const int MAXN = 100000;
int N, K;
int x1, y1, x2, y2;
vector <int> fac;
vector <vector<int>> c;
int cnt, ans;
void init() {
for (int i = 1; i < N; i++)
if (N % i == 0) fac.pb(i);
c.resize(fac.size());
for (vector <int> &v : c)
v.resize(2);
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> N >> K;
init();
for (int i = 0; i < K; i++) {
cin >> x1 >> y1 >> x2 >> y2;
for (int x = x1; x <= x2; x++) {
for (int y = y1; y <= y2; y++) {
int id = 0;
for (int p : fac) {
int t = ((x+p-1) / p) + ((y+p-1) / p);
c[id++][t & 1]++, cnt++;
}
}
}
}
ans = N * N;
cnt /= fac.size();
int id = 0;
for (int p : fac) {
int m1 = (N / p) * (N / p) / 2 * p * p;
int m0 = N * N - m1;
// debug(p, m0, m1);
// debug(m1 - c[id][1] + c[id][0]);
// debug(m0 - c[id][0] + c[id][1]);
ans = min(ans, m1 - c[id][1] + c[id][0]);
ans = min(ans, m0 - c[id][0] + c[id][1]);
id++;
}
cout << ans << '\n';
}
# | 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... |