이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using ll = long long;
using std::vector;
using std::array;
using std::pair;
using std::tuple;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int N, Q;
std::cin >> N >> Q;
vector<int> A(Q), B(Q), C(Q), D(Q);
for (int i = 0; i < Q; ++i) {
std::cin >> A[i] >> B[i] >> C[i] >> D[i];
A[i] -= 1;
B[i] -= 1;
}
const auto calc = [&](const int x, const int d) {
const int q = x / d;
const int r = x % d;
if (q % 2 == 0) {
return r;
} else {
return d - r;
}
};
ll ans = (ll)N * N;
for (int d = 1; d < N; ++d) {
if (N % d != 0) {
continue;
}
ll sum = 0;
for (int i = 0; i < Q; ++i) {
sum += (ll)(calc(C[i], d) - calc(A[i], d)) * (calc(D[i], d) - calc(B[i], d));
}
const ll dif = (ll)calc(N, d) * calc(N, d) - 2 * sum;
ans = std::min(ans, ((ll)N * N - std::abs(dif)) / 2);
}
std::cout << ans << '\n';
return 0;
}
# | 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... |