이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define int long long
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define in freopen("A.in", "r", stdin);
#define out freopen("A.out", "w", stdout);
using namespace std;
const int N = 500500;
const int INF = 1e15;
int TN = 1;
int n, k, ans = INF;
pair<int, int> a[N];
int get(int a, int b, int c) {
a--; b--;
a /= c; b /= c;
a++; b++;
return a + b;
}
int calc(int x) {
if (x == n) {
return INF;
}
// если первая фигня должна быть белой;
int res = (((n / x) * (n / x)) / 2) * x * x;
for (int i = 1; i <= k; i++) {
if (get(a[i].fi, a[i].se, x) % 2 == 0) {
res++;
}
else {
res--;
}
}
// иначе;
int tmp = (((n / x) * (n / x)) / 2 + (n / x) % 2) * x * x;
for (int i = 1; i <= k; i++) {
if (get(a[i].fi, a[i].se, x) % 2 == 0) {
tmp--;
}
else {
tmp++;
}
}
return min(res, tmp);
}
void solve() {
cin >> n >> k;
for (int i = 1; i <= k; i++) {
cin >> a[i].fi >> a[i].se >> a[i].fi >> a[i].se;
}
for (int i = 1; i * i <= n; i++) {
if (n % i == 0) {
if (i * i == n) {
ans = min(ans, calc(i));
}
else {
ans = min(ans, calc(i));
ans = min(ans, calc(n / i));
}
}
}
cout << ans << "\n";
return;
}
signed main() {
// ios_base::sync_with_stdio(0);
// in; out; // cin >> TN;
while (TN--) solve();
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... |