/*
// is short or still long ???
hollwo_pelw's template(short)
// Note : -Dhollwo_pelw_local
*/
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/trie_policy.hpp>
// #include <ext/rope>
using namespace std;
// using namespace __gnu_pbds;
// using namespace __gnu_cxx;
void FAST_IO(string filein = "", string fileout = "", string fileerr = ""){
if (fopen(filein.c_str(), "r")){
freopen(filein.c_str(), "r", stdin);
freopen(fileout.c_str(), "w", stdout);
#ifdef hollwo_pelw_local
freopen(fileerr.c_str(), "w", stderr);
#endif
}
cin.tie(0), cout.tie(0) -> sync_with_stdio(0);
}
void Hollwo_Pelw();
signed main(){
#ifdef hollwo_pelw_local
FAST_IO("input.inp", "output.out", "error.err");
auto start = chrono::steady_clock::now();
#else
FAST_IO("hollwo_pelw.inp", "hollwo_pelw.out");
#endif
int testcases = 1;
// cin >> testcases;
for (int test = 1; test <= testcases; test++){
// cout << "Case #" << test << ": ";
Hollwo_Pelw();
}
#ifdef hollwo_pelw_local
auto end = chrono::steady_clock::now();
cout << "\nExcution time : " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
#endif
return 0;
}
#define int long long
const int N = 1e5 + 5;
struct rect_t {
int x1, y1, x2, y2;
rect_t(int _x1 = 0, int _y1 = 0, int _x2 = 0, int _y2 = 0)
: x1(_x1), y1(_y1), x2(_x2), y2(_y2) {}
} a[N];
int n, m;
inline int get(int i, int k) {
return min(i % (2 * k), k) + i / (2 * k) * k;
}
inline int solve(int k) {
int cnt = n * n / (k * k);
int res = (cnt / 2) * (k * k);
// cout << "solve " << k << '\n';
for (int i = 1; i <= m; i++) {
auto [x1, y1, x2, y2] = a[i];
// cout << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << '\n';
int H = x2 - x1 + 1;
int W = y2 - y1 + 1;
int tot = H * W;
// cout << H << ' ' << W << '\n';
int h = get(x2, k) - get(x1 - 1, k);
int w = get(y2, k) - get(y1 - 1, k);
// cout << h << ' ' << w << '\n';
int black = h * w + (H - h) * (W - w);
res = res - tot + 2 * black;
}
return min(n * n - res, res);
}
void Hollwo_Pelw() {
cin >> n >> m;
for (int i = 1, x1, y1, x2, y2; i <= m; i++) {
cin >> x1 >> y1 >> x2 >> y2;
a[i] = rect_t(x1, y1, x2, y2);
}
int res = 1e18;
for (int i = 1; i < n; i++)
if (n % i == 0) res = min(res, solve(i));
cout << res;
}
Compilation message
chessboard.cpp: In function 'void FAST_IO(std::string, std::string, std::string)':
chessboard.cpp:18:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | freopen(filein.c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
chessboard.cpp:19:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
19 | freopen(fileout.c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3404 KB |
Output is correct |
2 |
Correct |
2 ms |
3440 KB |
Output is correct |
3 |
Correct |
2 ms |
3360 KB |
Output is correct |
4 |
Correct |
2 ms |
3404 KB |
Output is correct |
5 |
Correct |
2 ms |
3404 KB |
Output is correct |
6 |
Correct |
2 ms |
3404 KB |
Output is correct |
7 |
Correct |
2 ms |
3404 KB |
Output is correct |
8 |
Correct |
2 ms |
3404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
4836 KB |
Output is correct |
2 |
Correct |
7 ms |
3788 KB |
Output is correct |
3 |
Correct |
15 ms |
4320 KB |
Output is correct |
4 |
Correct |
15 ms |
4200 KB |
Output is correct |
5 |
Correct |
21 ms |
4740 KB |
Output is correct |
6 |
Correct |
14 ms |
4172 KB |
Output is correct |
7 |
Correct |
4 ms |
3536 KB |
Output is correct |
8 |
Correct |
14 ms |
4300 KB |
Output is correct |
9 |
Correct |
29 ms |
5460 KB |
Output is correct |
10 |
Correct |
18 ms |
4604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3444 KB |
Output is correct |
2 |
Correct |
2 ms |
3404 KB |
Output is correct |
3 |
Correct |
2 ms |
3404 KB |
Output is correct |
4 |
Correct |
2 ms |
3404 KB |
Output is correct |
5 |
Correct |
2 ms |
3404 KB |
Output is correct |
6 |
Correct |
2 ms |
3404 KB |
Output is correct |
7 |
Correct |
2 ms |
3404 KB |
Output is correct |
8 |
Correct |
2 ms |
3452 KB |
Output is correct |
9 |
Correct |
2 ms |
3404 KB |
Output is correct |
10 |
Correct |
2 ms |
3404 KB |
Output is correct |
11 |
Correct |
2 ms |
3448 KB |
Output is correct |
12 |
Correct |
2 ms |
3404 KB |
Output is correct |
13 |
Correct |
2 ms |
3404 KB |
Output is correct |
14 |
Correct |
2 ms |
3404 KB |
Output is correct |
15 |
Correct |
2 ms |
3452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3444 KB |
Output is correct |
2 |
Correct |
2 ms |
3404 KB |
Output is correct |
3 |
Correct |
2 ms |
3404 KB |
Output is correct |
4 |
Correct |
2 ms |
3404 KB |
Output is correct |
5 |
Correct |
2 ms |
3404 KB |
Output is correct |
6 |
Correct |
2 ms |
3404 KB |
Output is correct |
7 |
Correct |
2 ms |
3404 KB |
Output is correct |
8 |
Correct |
2 ms |
3452 KB |
Output is correct |
9 |
Correct |
2 ms |
3404 KB |
Output is correct |
10 |
Correct |
2 ms |
3404 KB |
Output is correct |
11 |
Correct |
2 ms |
3448 KB |
Output is correct |
12 |
Correct |
2 ms |
3404 KB |
Output is correct |
13 |
Correct |
2 ms |
3404 KB |
Output is correct |
14 |
Correct |
2 ms |
3404 KB |
Output is correct |
15 |
Correct |
2 ms |
3452 KB |
Output is correct |
16 |
Correct |
10 ms |
3788 KB |
Output is correct |
17 |
Correct |
23 ms |
4700 KB |
Output is correct |
18 |
Correct |
33 ms |
4936 KB |
Output is correct |
19 |
Correct |
73 ms |
4828 KB |
Output is correct |
20 |
Correct |
80 ms |
5060 KB |
Output is correct |
21 |
Correct |
23 ms |
4708 KB |
Output is correct |
22 |
Correct |
2 ms |
3404 KB |
Output is correct |
23 |
Correct |
18 ms |
4068 KB |
Output is correct |
24 |
Correct |
29 ms |
4812 KB |
Output is correct |
25 |
Correct |
5 ms |
3532 KB |
Output is correct |
26 |
Correct |
18 ms |
4356 KB |
Output is correct |
27 |
Correct |
25 ms |
4548 KB |
Output is correct |
28 |
Correct |
34 ms |
4988 KB |
Output is correct |
29 |
Correct |
11 ms |
3988 KB |
Output is correct |
30 |
Correct |
3 ms |
3404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
4836 KB |
Output is correct |
2 |
Correct |
7 ms |
3788 KB |
Output is correct |
3 |
Correct |
15 ms |
4320 KB |
Output is correct |
4 |
Correct |
15 ms |
4200 KB |
Output is correct |
5 |
Correct |
21 ms |
4740 KB |
Output is correct |
6 |
Correct |
14 ms |
4172 KB |
Output is correct |
7 |
Correct |
4 ms |
3536 KB |
Output is correct |
8 |
Correct |
14 ms |
4300 KB |
Output is correct |
9 |
Correct |
29 ms |
5460 KB |
Output is correct |
10 |
Correct |
18 ms |
4604 KB |
Output is correct |
11 |
Correct |
2 ms |
3444 KB |
Output is correct |
12 |
Correct |
2 ms |
3404 KB |
Output is correct |
13 |
Correct |
2 ms |
3404 KB |
Output is correct |
14 |
Correct |
2 ms |
3404 KB |
Output is correct |
15 |
Correct |
2 ms |
3404 KB |
Output is correct |
16 |
Correct |
2 ms |
3404 KB |
Output is correct |
17 |
Correct |
2 ms |
3404 KB |
Output is correct |
18 |
Correct |
2 ms |
3452 KB |
Output is correct |
19 |
Correct |
2 ms |
3404 KB |
Output is correct |
20 |
Correct |
2 ms |
3404 KB |
Output is correct |
21 |
Correct |
2 ms |
3448 KB |
Output is correct |
22 |
Correct |
2 ms |
3404 KB |
Output is correct |
23 |
Correct |
2 ms |
3404 KB |
Output is correct |
24 |
Correct |
2 ms |
3404 KB |
Output is correct |
25 |
Correct |
2 ms |
3452 KB |
Output is correct |
26 |
Correct |
10 ms |
3788 KB |
Output is correct |
27 |
Correct |
23 ms |
4700 KB |
Output is correct |
28 |
Correct |
33 ms |
4936 KB |
Output is correct |
29 |
Correct |
73 ms |
4828 KB |
Output is correct |
30 |
Correct |
80 ms |
5060 KB |
Output is correct |
31 |
Correct |
23 ms |
4708 KB |
Output is correct |
32 |
Correct |
2 ms |
3404 KB |
Output is correct |
33 |
Correct |
18 ms |
4068 KB |
Output is correct |
34 |
Correct |
29 ms |
4812 KB |
Output is correct |
35 |
Correct |
5 ms |
3532 KB |
Output is correct |
36 |
Correct |
18 ms |
4356 KB |
Output is correct |
37 |
Correct |
25 ms |
4548 KB |
Output is correct |
38 |
Correct |
34 ms |
4988 KB |
Output is correct |
39 |
Correct |
11 ms |
3988 KB |
Output is correct |
40 |
Correct |
3 ms |
3404 KB |
Output is correct |
41 |
Correct |
73 ms |
5340 KB |
Output is correct |
42 |
Correct |
37 ms |
5572 KB |
Output is correct |
43 |
Correct |
48 ms |
5316 KB |
Output is correct |
44 |
Correct |
34 ms |
5576 KB |
Output is correct |
45 |
Correct |
33 ms |
5728 KB |
Output is correct |
46 |
Correct |
85 ms |
5700 KB |
Output is correct |
47 |
Correct |
30 ms |
5468 KB |
Output is correct |
48 |
Correct |
43 ms |
5472 KB |
Output is correct |
49 |
Correct |
33 ms |
5352 KB |
Output is correct |
50 |
Correct |
299 ms |
5600 KB |
Output is correct |
51 |
Correct |
306 ms |
5736 KB |
Output is correct |
52 |
Correct |
296 ms |
5572 KB |
Output is correct |
53 |
Correct |
319 ms |
5720 KB |
Output is correct |
54 |
Correct |
282 ms |
5492 KB |
Output is correct |
55 |
Correct |
314 ms |
5808 KB |
Output is correct |
56 |
Correct |
270 ms |
5480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3404 KB |
Output is correct |
2 |
Correct |
2 ms |
3440 KB |
Output is correct |
3 |
Correct |
2 ms |
3360 KB |
Output is correct |
4 |
Correct |
2 ms |
3404 KB |
Output is correct |
5 |
Correct |
2 ms |
3404 KB |
Output is correct |
6 |
Correct |
2 ms |
3404 KB |
Output is correct |
7 |
Correct |
2 ms |
3404 KB |
Output is correct |
8 |
Correct |
2 ms |
3404 KB |
Output is correct |
9 |
Correct |
23 ms |
4836 KB |
Output is correct |
10 |
Correct |
7 ms |
3788 KB |
Output is correct |
11 |
Correct |
15 ms |
4320 KB |
Output is correct |
12 |
Correct |
15 ms |
4200 KB |
Output is correct |
13 |
Correct |
21 ms |
4740 KB |
Output is correct |
14 |
Correct |
14 ms |
4172 KB |
Output is correct |
15 |
Correct |
4 ms |
3536 KB |
Output is correct |
16 |
Correct |
14 ms |
4300 KB |
Output is correct |
17 |
Correct |
29 ms |
5460 KB |
Output is correct |
18 |
Correct |
18 ms |
4604 KB |
Output is correct |
19 |
Correct |
2 ms |
3444 KB |
Output is correct |
20 |
Correct |
2 ms |
3404 KB |
Output is correct |
21 |
Correct |
2 ms |
3404 KB |
Output is correct |
22 |
Correct |
2 ms |
3404 KB |
Output is correct |
23 |
Correct |
2 ms |
3404 KB |
Output is correct |
24 |
Correct |
2 ms |
3404 KB |
Output is correct |
25 |
Correct |
2 ms |
3404 KB |
Output is correct |
26 |
Correct |
2 ms |
3452 KB |
Output is correct |
27 |
Correct |
2 ms |
3404 KB |
Output is correct |
28 |
Correct |
2 ms |
3404 KB |
Output is correct |
29 |
Correct |
2 ms |
3448 KB |
Output is correct |
30 |
Correct |
2 ms |
3404 KB |
Output is correct |
31 |
Correct |
2 ms |
3404 KB |
Output is correct |
32 |
Correct |
2 ms |
3404 KB |
Output is correct |
33 |
Correct |
2 ms |
3452 KB |
Output is correct |
34 |
Correct |
10 ms |
3788 KB |
Output is correct |
35 |
Correct |
23 ms |
4700 KB |
Output is correct |
36 |
Correct |
33 ms |
4936 KB |
Output is correct |
37 |
Correct |
73 ms |
4828 KB |
Output is correct |
38 |
Correct |
80 ms |
5060 KB |
Output is correct |
39 |
Correct |
23 ms |
4708 KB |
Output is correct |
40 |
Correct |
2 ms |
3404 KB |
Output is correct |
41 |
Correct |
18 ms |
4068 KB |
Output is correct |
42 |
Correct |
29 ms |
4812 KB |
Output is correct |
43 |
Correct |
5 ms |
3532 KB |
Output is correct |
44 |
Correct |
18 ms |
4356 KB |
Output is correct |
45 |
Correct |
25 ms |
4548 KB |
Output is correct |
46 |
Correct |
34 ms |
4988 KB |
Output is correct |
47 |
Correct |
11 ms |
3988 KB |
Output is correct |
48 |
Correct |
3 ms |
3404 KB |
Output is correct |
49 |
Correct |
73 ms |
5340 KB |
Output is correct |
50 |
Correct |
37 ms |
5572 KB |
Output is correct |
51 |
Correct |
48 ms |
5316 KB |
Output is correct |
52 |
Correct |
34 ms |
5576 KB |
Output is correct |
53 |
Correct |
33 ms |
5728 KB |
Output is correct |
54 |
Correct |
85 ms |
5700 KB |
Output is correct |
55 |
Correct |
30 ms |
5468 KB |
Output is correct |
56 |
Correct |
43 ms |
5472 KB |
Output is correct |
57 |
Correct |
33 ms |
5352 KB |
Output is correct |
58 |
Correct |
299 ms |
5600 KB |
Output is correct |
59 |
Correct |
306 ms |
5736 KB |
Output is correct |
60 |
Correct |
296 ms |
5572 KB |
Output is correct |
61 |
Correct |
319 ms |
5720 KB |
Output is correct |
62 |
Correct |
282 ms |
5492 KB |
Output is correct |
63 |
Correct |
314 ms |
5808 KB |
Output is correct |
64 |
Correct |
270 ms |
5480 KB |
Output is correct |
65 |
Correct |
2 ms |
3404 KB |
Output is correct |
66 |
Correct |
2 ms |
3404 KB |
Output is correct |
67 |
Correct |
312 ms |
5656 KB |
Output is correct |
68 |
Correct |
304 ms |
5640 KB |
Output is correct |
69 |
Correct |
263 ms |
5324 KB |
Output is correct |
70 |
Correct |
293 ms |
5596 KB |
Output is correct |
71 |
Correct |
283 ms |
5552 KB |
Output is correct |
72 |
Correct |
275 ms |
5572 KB |
Output is correct |
73 |
Correct |
274 ms |
5444 KB |
Output is correct |
74 |
Correct |
289 ms |
5724 KB |
Output is correct |
75 |
Correct |
293 ms |
5548 KB |
Output is correct |
76 |
Correct |
299 ms |
5720 KB |
Output is correct |
77 |
Correct |
65 ms |
5796 KB |
Output is correct |
78 |
Correct |
38 ms |
5468 KB |
Output is correct |
79 |
Correct |
47 ms |
5456 KB |
Output is correct |
80 |
Correct |
49 ms |
5572 KB |
Output is correct |
81 |
Correct |
50 ms |
5344 KB |
Output is correct |
82 |
Correct |
44 ms |
5596 KB |
Output is correct |
83 |
Correct |
38 ms |
5472 KB |
Output is correct |
84 |
Correct |
200 ms |
5828 KB |
Output is correct |
85 |
Correct |
316 ms |
5700 KB |
Output is correct |
86 |
Correct |
2 ms |
3404 KB |
Output is correct |
87 |
Correct |
2 ms |
3448 KB |
Output is correct |
88 |
Correct |
315 ms |
5820 KB |
Output is correct |
89 |
Correct |
62 ms |
3788 KB |
Output is correct |
90 |
Correct |
2 ms |
3444 KB |
Output is correct |