#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i)
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const ll INF = 1e18;
#define int long long
using node = tuple<int, int, int, int>;
int answer = INF;
vector<node> adj;
int n, kk;
int f(int x, int y, int xx){
int sm = 0, _x = (x/xx)*xx, _y = (y/xx)*xx;
if((_x/xx+_y/xx)&1){
sm += ((_x/xx)*(_y/xx))/2*(xx*xx);
sm += (_y/xx+1)/2*(x-_x)*xx;
sm += (_x/xx+1)/2*(y-_y)*xx;
}
else{
sm += ((_x/xx)*(_y /xx)+1)/2*(xx*xx);
sm += (_y/xx)/2*(x-_x)*xx;
sm += ((_x/xx))/2*(y-_y)*xx;
sm += (x-_x)*(y-_y);
}
return sm;
}
void solve(int x){
int ans = n*n-f(n, n, x);
for(auto xx : adj){
int a, b, c, d;
tie(a, b, c, d) = xx;
int w = f(c, d, x)+f(a-1, b-1, x)-f(c, b-1, x)-f(a-1, d, x);
ans += w, ans -= (c-a+1)*(d-b+1)-w;
}
umin(answer, ans);
umin(answer, n*n-ans);
}
signed main(){
// freopen("file.txt", "r", stdin);
scanf("%lld%lld", &n, &kk);
bool done = 1;
for(int i = 1; i <= kk; ++i){
int a, b, c, d;
scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
adj.pb({a, b, c, d});
done |= (a==c and b==d);
}
assert(done);
for(int i = 1; i*i <= n; ++i){
if(n%i==0){
solve(i);
if(i!=n/i and i>1)
solve(n/i);
}
}
printf("%lld\n", answer);
return 0;
}
Compilation message
chessboard.cpp: In function 'int main()':
chessboard.cpp:52:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
52 | scanf("%lld%lld", &n, &kk);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
chessboard.cpp:56:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
508 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
3524 KB |
Output is correct |
2 |
Correct |
5 ms |
1456 KB |
Output is correct |
3 |
Correct |
12 ms |
3524 KB |
Output is correct |
4 |
Correct |
13 ms |
3524 KB |
Output is correct |
5 |
Correct |
16 ms |
3524 KB |
Output is correct |
6 |
Correct |
11 ms |
3540 KB |
Output is correct |
7 |
Correct |
3 ms |
728 KB |
Output is correct |
8 |
Correct |
12 ms |
3524 KB |
Output is correct |
9 |
Correct |
25 ms |
6592 KB |
Output is correct |
10 |
Correct |
15 ms |
3540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
508 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
508 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
508 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
508 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
9 ms |
1480 KB |
Output is correct |
17 |
Correct |
26 ms |
6508 KB |
Output is correct |
18 |
Correct |
31 ms |
6716 KB |
Output is correct |
19 |
Correct |
89 ms |
6592 KB |
Output is correct |
20 |
Correct |
100 ms |
6592 KB |
Output is correct |
21 |
Correct |
21 ms |
6592 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
23 ms |
3620 KB |
Output is correct |
24 |
Correct |
27 ms |
6592 KB |
Output is correct |
25 |
Correct |
5 ms |
972 KB |
Output is correct |
26 |
Correct |
19 ms |
3524 KB |
Output is correct |
27 |
Correct |
26 ms |
6592 KB |
Output is correct |
28 |
Correct |
28 ms |
6592 KB |
Output is correct |
29 |
Correct |
9 ms |
3688 KB |
Output is correct |
30 |
Correct |
2 ms |
760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
3524 KB |
Output is correct |
2 |
Correct |
5 ms |
1456 KB |
Output is correct |
3 |
Correct |
12 ms |
3524 KB |
Output is correct |
4 |
Correct |
13 ms |
3524 KB |
Output is correct |
5 |
Correct |
16 ms |
3524 KB |
Output is correct |
6 |
Correct |
11 ms |
3540 KB |
Output is correct |
7 |
Correct |
3 ms |
728 KB |
Output is correct |
8 |
Correct |
12 ms |
3524 KB |
Output is correct |
9 |
Correct |
25 ms |
6592 KB |
Output is correct |
10 |
Correct |
15 ms |
3540 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
508 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
508 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
9 ms |
1480 KB |
Output is correct |
27 |
Correct |
26 ms |
6508 KB |
Output is correct |
28 |
Correct |
31 ms |
6716 KB |
Output is correct |
29 |
Correct |
89 ms |
6592 KB |
Output is correct |
30 |
Correct |
100 ms |
6592 KB |
Output is correct |
31 |
Correct |
21 ms |
6592 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
23 ms |
3620 KB |
Output is correct |
34 |
Correct |
27 ms |
6592 KB |
Output is correct |
35 |
Correct |
5 ms |
972 KB |
Output is correct |
36 |
Correct |
19 ms |
3524 KB |
Output is correct |
37 |
Correct |
26 ms |
6592 KB |
Output is correct |
38 |
Correct |
28 ms |
6592 KB |
Output is correct |
39 |
Correct |
9 ms |
3688 KB |
Output is correct |
40 |
Correct |
2 ms |
760 KB |
Output is correct |
41 |
Correct |
74 ms |
6592 KB |
Output is correct |
42 |
Correct |
30 ms |
6520 KB |
Output is correct |
43 |
Correct |
52 ms |
6592 KB |
Output is correct |
44 |
Correct |
31 ms |
6592 KB |
Output is correct |
45 |
Correct |
27 ms |
6720 KB |
Output is correct |
46 |
Correct |
89 ms |
6592 KB |
Output is correct |
47 |
Correct |
24 ms |
6592 KB |
Output is correct |
48 |
Correct |
39 ms |
6592 KB |
Output is correct |
49 |
Correct |
28 ms |
6584 KB |
Output is correct |
50 |
Correct |
361 ms |
6640 KB |
Output is correct |
51 |
Correct |
363 ms |
6760 KB |
Output is correct |
52 |
Correct |
352 ms |
6592 KB |
Output is correct |
53 |
Correct |
360 ms |
6604 KB |
Output is correct |
54 |
Correct |
340 ms |
6592 KB |
Output is correct |
55 |
Correct |
375 ms |
6716 KB |
Output is correct |
56 |
Correct |
323 ms |
6592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
508 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
18 ms |
3524 KB |
Output is correct |
10 |
Correct |
5 ms |
1456 KB |
Output is correct |
11 |
Correct |
12 ms |
3524 KB |
Output is correct |
12 |
Correct |
13 ms |
3524 KB |
Output is correct |
13 |
Correct |
16 ms |
3524 KB |
Output is correct |
14 |
Correct |
11 ms |
3540 KB |
Output is correct |
15 |
Correct |
3 ms |
728 KB |
Output is correct |
16 |
Correct |
12 ms |
3524 KB |
Output is correct |
17 |
Correct |
25 ms |
6592 KB |
Output is correct |
18 |
Correct |
15 ms |
3540 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
508 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
508 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
9 ms |
1480 KB |
Output is correct |
35 |
Correct |
26 ms |
6508 KB |
Output is correct |
36 |
Correct |
31 ms |
6716 KB |
Output is correct |
37 |
Correct |
89 ms |
6592 KB |
Output is correct |
38 |
Correct |
100 ms |
6592 KB |
Output is correct |
39 |
Correct |
21 ms |
6592 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
23 ms |
3620 KB |
Output is correct |
42 |
Correct |
27 ms |
6592 KB |
Output is correct |
43 |
Correct |
5 ms |
972 KB |
Output is correct |
44 |
Correct |
19 ms |
3524 KB |
Output is correct |
45 |
Correct |
26 ms |
6592 KB |
Output is correct |
46 |
Correct |
28 ms |
6592 KB |
Output is correct |
47 |
Correct |
9 ms |
3688 KB |
Output is correct |
48 |
Correct |
2 ms |
760 KB |
Output is correct |
49 |
Correct |
74 ms |
6592 KB |
Output is correct |
50 |
Correct |
30 ms |
6520 KB |
Output is correct |
51 |
Correct |
52 ms |
6592 KB |
Output is correct |
52 |
Correct |
31 ms |
6592 KB |
Output is correct |
53 |
Correct |
27 ms |
6720 KB |
Output is correct |
54 |
Correct |
89 ms |
6592 KB |
Output is correct |
55 |
Correct |
24 ms |
6592 KB |
Output is correct |
56 |
Correct |
39 ms |
6592 KB |
Output is correct |
57 |
Correct |
28 ms |
6584 KB |
Output is correct |
58 |
Correct |
361 ms |
6640 KB |
Output is correct |
59 |
Correct |
363 ms |
6760 KB |
Output is correct |
60 |
Correct |
352 ms |
6592 KB |
Output is correct |
61 |
Correct |
360 ms |
6604 KB |
Output is correct |
62 |
Correct |
340 ms |
6592 KB |
Output is correct |
63 |
Correct |
375 ms |
6716 KB |
Output is correct |
64 |
Correct |
323 ms |
6592 KB |
Output is correct |
65 |
Correct |
1 ms |
336 KB |
Output is correct |
66 |
Correct |
1 ms |
336 KB |
Output is correct |
67 |
Correct |
375 ms |
6592 KB |
Output is correct |
68 |
Correct |
380 ms |
6592 KB |
Output is correct |
69 |
Correct |
320 ms |
6592 KB |
Output is correct |
70 |
Correct |
355 ms |
6592 KB |
Output is correct |
71 |
Correct |
353 ms |
6592 KB |
Output is correct |
72 |
Correct |
348 ms |
6584 KB |
Output is correct |
73 |
Correct |
346 ms |
6592 KB |
Output is correct |
74 |
Correct |
378 ms |
6592 KB |
Output is correct |
75 |
Correct |
360 ms |
6592 KB |
Output is correct |
76 |
Correct |
375 ms |
6592 KB |
Output is correct |
77 |
Correct |
70 ms |
6592 KB |
Output is correct |
78 |
Correct |
29 ms |
6592 KB |
Output is correct |
79 |
Correct |
49 ms |
6712 KB |
Output is correct |
80 |
Correct |
53 ms |
6592 KB |
Output is correct |
81 |
Correct |
49 ms |
6604 KB |
Output is correct |
82 |
Correct |
44 ms |
6592 KB |
Output is correct |
83 |
Correct |
42 ms |
6592 KB |
Output is correct |
84 |
Correct |
225 ms |
6592 KB |
Output is correct |
85 |
Correct |
396 ms |
6736 KB |
Output is correct |
86 |
Correct |
1 ms |
336 KB |
Output is correct |
87 |
Correct |
1 ms |
336 KB |
Output is correct |
88 |
Correct |
395 ms |
6592 KB |
Output is correct |
89 |
Correct |
82 ms |
1480 KB |
Output is correct |
90 |
Correct |
1 ms |
336 KB |
Output is correct |