이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 a = 0, b = 0;
for(int i = 1; i <= n; ++i) {
if(i & 1) a += n / 2, b += (n + 1) / 2;
else a += (n + 1) / 2, b += n / 2;
}
while(k--) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
if(x1 & 1) {
if(y1 & 1) a++, b--;
else a--, b++;
} else {
if(y1 & 1) a--, b++;
else a++, b--;
}
for(int i = x1; i <= x2; ++i) {
for(int j = y1; j <= y2; ++j) {
c[i][j] = 1;
}
}
}
int ans = min(a, b);
for(int i = 2; i < n; ++i) {
if(n % i == 0) {
ans = min(ans, f(i, 0));
ans = min(ans, f(i, 1));
}
}
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;
}
# | 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... |