// O O O O O O O O O O O O O O O OO O OO O OO O O O TTCH O TTTCH O TTTCH O O O O
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("no-stack-protector")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx")
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <random>
#include <iomanip>
#include <bitset>
#include <cassert>
using namespace std;
#define int long long
#define y1 y11
#define double long double
#define less less228
#define left left228
#define right right228
#define list list228
template<typename T> void uin(T &a, T b) {
if (b < a) a = b;
}
template<typename T> void uax(T &a, T b) {
if (b > a) a = b;
}
random_device rnd;
template<typename T> void shuffle(vector< T > &v) {
for (int i = 1; i < (int)v.size(); ++i) {
swap(v[rnd() % i], v[i]);
}
for (int i = (int)v.size() - 1; i; --i) {
swap(v[rnd() % i], v[i]);
}
}
const int INF = 1e9 + 228;
const int N = 100 * 1000 + 228;
vector<int> get_divisors(int n) {
int i = 1;
vector<int> v;
while (i * i <= n) {
if (n % i == 0) {
v.push_back(i);
if (n / i != i && i != 1) {
v.push_back(n / i);
}
}
++i;
}
sort(v.begin(), v.end());
return v;
}
pair<int, int> get(int x1, int y1, int x2, int y2) {
int white = (x2 - x1 + 1) * (y2 - y1 + 1) / 2;
int black = white;
if ( ((x2 - x1 + 1) * (y2 - y1 + 1)) % 2 == 1 ) {
if ((x1 + y1) % 2 == 0) ++white;
else ++black;
}
return {white, black};
}
int a[1005][1005];
int b[1005][1005];
int n, k;
int x1[N], y1[N], x2[N], y2[N];
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
for (int i = 1; i <= k; ++i) {
cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
for (int x = x1[i]; x <= x2[i]; ++x) {
for (int y = y1[i]; y <= y2[i]; ++y) {
b[x][y] = 1;
}
}
}
vector<int> div = get_divisors(n);
int res = INF;
for (int d : div) {
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
a[i][j] = 0;
if (((i - 1) / d + (j - 1) / d) & 1) {
a[i][j] = 1;
}
}
}
int cur = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
cur += (a[i][j] ^ b[i][j]);
a[i][j] ^= 1;
}
}
uin(res, cur);
cur = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
cur += (a[i][j] ^ b[i][j]);
}
}
uin(res, cur);
}
cout << res << '\n';
return 0;
}
// RU_023
/*
2 0
6 8
3 3 3 3
1 2 1 2
3 4 3 4
5 5 5 5
4 3 4 3
4 4 4 4
2 1 2 1
3 6 3 6
4 1
4 1 4 4
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
888 KB |
Output is correct |
3 |
Correct |
4 ms |
892 KB |
Output is correct |
4 |
Correct |
3 ms |
760 KB |
Output is correct |
5 |
Correct |
3 ms |
632 KB |
Output is correct |
6 |
Correct |
4 ms |
760 KB |
Output is correct |
7 |
Correct |
3 ms |
760 KB |
Output is correct |
8 |
Correct |
4 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1016 KB |
Output is correct |
2 |
Correct |
2 ms |
760 KB |
Output is correct |
3 |
Correct |
2 ms |
1016 KB |
Output is correct |
4 |
Correct |
4 ms |
1168 KB |
Output is correct |
5 |
Correct |
3 ms |
1040 KB |
Output is correct |
6 |
Correct |
3 ms |
1016 KB |
Output is correct |
7 |
Correct |
3 ms |
1144 KB |
Output is correct |
8 |
Correct |
4 ms |
1016 KB |
Output is correct |
9 |
Correct |
3 ms |
1272 KB |
Output is correct |
10 |
Correct |
2 ms |
860 KB |
Output is correct |
11 |
Correct |
1 ms |
888 KB |
Output is correct |
12 |
Correct |
2 ms |
940 KB |
Output is correct |
13 |
Correct |
4 ms |
1016 KB |
Output is correct |
14 |
Correct |
4 ms |
1144 KB |
Output is correct |
15 |
Correct |
3 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1016 KB |
Output is correct |
2 |
Correct |
2 ms |
760 KB |
Output is correct |
3 |
Correct |
2 ms |
1016 KB |
Output is correct |
4 |
Correct |
4 ms |
1168 KB |
Output is correct |
5 |
Correct |
3 ms |
1040 KB |
Output is correct |
6 |
Correct |
3 ms |
1016 KB |
Output is correct |
7 |
Correct |
3 ms |
1144 KB |
Output is correct |
8 |
Correct |
4 ms |
1016 KB |
Output is correct |
9 |
Correct |
3 ms |
1272 KB |
Output is correct |
10 |
Correct |
2 ms |
860 KB |
Output is correct |
11 |
Correct |
1 ms |
888 KB |
Output is correct |
12 |
Correct |
2 ms |
940 KB |
Output is correct |
13 |
Correct |
4 ms |
1016 KB |
Output is correct |
14 |
Correct |
4 ms |
1144 KB |
Output is correct |
15 |
Correct |
3 ms |
860 KB |
Output is correct |
16 |
Correct |
76 ms |
16708 KB |
Output is correct |
17 |
Correct |
72 ms |
20104 KB |
Output is correct |
18 |
Correct |
109 ms |
20792 KB |
Output is correct |
19 |
Correct |
437 ms |
19724 KB |
Output is correct |
20 |
Correct |
437 ms |
20240 KB |
Output is correct |
21 |
Correct |
70 ms |
19976 KB |
Output is correct |
22 |
Correct |
225 ms |
9956 KB |
Output is correct |
23 |
Correct |
132 ms |
17708 KB |
Output is correct |
24 |
Correct |
102 ms |
20376 KB |
Output is correct |
25 |
Correct |
117 ms |
15988 KB |
Output is correct |
26 |
Correct |
92 ms |
18148 KB |
Output is correct |
27 |
Correct |
119 ms |
18828 KB |
Output is correct |
28 |
Correct |
101 ms |
20020 KB |
Output is correct |
29 |
Correct |
42 ms |
17044 KB |
Output is correct |
30 |
Correct |
57 ms |
14128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
888 KB |
Output is correct |
3 |
Correct |
4 ms |
892 KB |
Output is correct |
4 |
Correct |
3 ms |
760 KB |
Output is correct |
5 |
Correct |
3 ms |
632 KB |
Output is correct |
6 |
Correct |
4 ms |
760 KB |
Output is correct |
7 |
Correct |
3 ms |
760 KB |
Output is correct |
8 |
Correct |
4 ms |
760 KB |
Output is correct |
9 |
Runtime error |
2 ms |
632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
10 |
Halted |
0 ms |
0 KB |
- |