# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
892993 | vjudge1 | Chessboard (IZhO18_chessboard) | C++17 | 132 ms | 9240 KiB |
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>
#ifdef local
#include "algo/debug.h"
#else
#define dbg(x...) 0
#endif
using namespace std ;
using ll = long long ;
bool isPrime(int x) {
if (x < 2) return 0 ;
for (int i = 2 ; i * i <= x ; i++) {
if (x % i == 0) {
return 0 ;
}
}
return 1 ;
}
int32_t main() {
cin.tie(0)->sync_with_stdio(false) ;
ll n, k ; cin >> n >> k ;
struct rect {
int x1, y1, x2, y2;
void read() {
cin >> x1 >> y1 >> x2 >> y2 ;
x1--, y1-- , x2-- , y2-- ;
}
};
vector<rect> a(k) ;
for (int i = 0 ; i < k ; i++) a[i].read() ;
vector<int> d;
for (int i = 1 ; i * i <= n ; i++) {
if (n % i) continue ;
d.push_back(i) ;
if (n / i != i) d.push_back(n / i) ;
}
auto calc = [&](ll del) -> ll{
vector<vector<ll>> cnt(n, vector<ll>(2, 0)) ;
int block = n / del ;
for (int i = 0 ; i < k ; i++) {
int x1 = a[i].x1 , y1 = a[i].y1 , x2 = a[i].x2, y2 = a[i].y2 ;
cnt[x1 / block][(y1 / block) % 2]++;
}
dbg(cnt) ;
ll ret = 0 , sum = 0 ;
for (int i = 0 ; i < del ; i++) {
// for (int j = 0 ; j < del ; j++) {
if (i % 2 == 0) {
ll c = ((del + 1) / 2) * (block * block) ;
ll cur = c - cnt[i][0] + cnt[i][1] ;
sum += cur ;
} else {
ll c = (del / 2) * (block * block) ;
ll cur = c - cnt[i][1] + cnt[i][0] ;
sum += cur ;
}
// }
}
ret = sum ;
sum = 0 ;
for (int i = 0 ; i < del ; i++) {
// for (int j = 0 ; j < del ; j++) {
if (i % 2 != 0) {
ll c = ((del + 1) / 2) * (block * block) ;
ll cur = c - cnt[i][0] + cnt[i][1] ;
sum += cur ;
} else {
ll c = (del / 2) * (block * block) ;
ll cur = c - cnt[i][1] + cnt[i][0] ;
sum += cur ;
}
// }
}
ret = min(ret, sum) ;
return ret ;
};
ll ret = LLONG_MAX ;
for (int i : d) {
dbg(i, calc(i)) ;
if (i > 1)
ret = min(ret, calc(i)) ;
}
cout << ret ;
return 0 ;
}
// 希望白银
Compilation message (stderr)
# | 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... |