// -- //
#include <bits/stdc++.h>
#define pll pair<ll, ll>
#define ppll pair<pll, pll>
#define x first
#define y second
using namespace std;
typedef long long ll;
const ll N = 1e5+228;
ppll a[N];
vector<pll> add[N], del[N];
ll res, n, k;
inline void ch(ll m) __attribute__((always_inline));
inline void ch(ll m){
ll bob=0, bow=0;
//wbw
//bwb
ll no[2]={0};
bool fl=0;
ll kk=0;
for(ll i = 1;i<=n;i++, kk++){
for(auto &j : add[i]){
ll s = j.x, e = j.y;
--s, e--;
ll bs = s/m, be = e/m, bse = (bs+1)*m-1, bes = (be)*m;
if(bs==be) no[bs&1] += e-s+1;
else if(bs+1==be){
no[bs&1] += bse-s+1;
no[be&1] += e-bes+1;
}else{
no[bs&1] += bse-s+1;
no[be&1] += e-bes+1;
bs++, be--;
ll kb = (be-bs+1)/2;
no[bs&1] += (be-bs+1-kb)*m;
no[(bs&1)^1] += kb*m;
}
}
if(((i-1)/m)&1){
bow+=no[0], bob+=no[1];
}else{
bob+=no[0], bow+=no[1];
}
for(auto &j : del[i]){
ll s = j.x, e = j.y;
--s, e--;
ll bs = s/m, be = e/m, bse = (bs+1)*m-1, bes = (be)*m;
if(bs==be) no[bs&1] -= e-s+1;
else if(bs+1==be){
no[bs&1] -= bse-s+1;
no[be&1] -= e-bes+1;
}else{
no[bs&1] -= bse-s+1;
no[be&1] -= e-bes+1;
bs++, be--;
ll kb = (be-bs+1)/2;
no[bs&1] -= (be-bs+1-kb)*m;
no[(bs&1)^1] -= kb*m;
}
}
}
ll bln = n/m;
ll mbb = (bln/2)*m*n+((bln&1) ? (bln/2)+1 : 0)*m*m;
ll v1 = (mbb-bob)+bow;
ll v2 = bob+(n*n-mbb-bow);
if(v1<res) res=v1;
if(v2<res) res=v2;
}
signed main(){
cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
cin >> n >> k;
for(ll i =0 ;i<k;i++){
cin >> a[i].x.x >> a[i].x.y >> a[i].y.x >> a[i].y.y;
add[a[i].x.y].push_back({a[i].x.x, a[i].y.x});
del[a[i].y.y].push_back({a[i].x.x, a[i].y.x});
}
res=n*n;
for(ll i = 1;i*i<=n;i++){
if(n%i) continue;
ch(i);
if(i>1) ch(n/i);
}
cout<<res;
}
Compilation message
chessboard.cpp: In function 'void ch(ll)':
chessboard.cpp:19:10: warning: unused variable 'fl' [-Wunused-variable]
19 | bool fl=0;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5100 KB |
Output is correct |
2 |
Correct |
5 ms |
5100 KB |
Output is correct |
3 |
Correct |
4 ms |
5100 KB |
Output is correct |
4 |
Correct |
4 ms |
5100 KB |
Output is correct |
5 |
Correct |
4 ms |
5100 KB |
Output is correct |
6 |
Correct |
4 ms |
5100 KB |
Output is correct |
7 |
Correct |
4 ms |
5100 KB |
Output is correct |
8 |
Correct |
4 ms |
5100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
10476 KB |
Output is correct |
2 |
Correct |
14 ms |
6508 KB |
Output is correct |
3 |
Correct |
39 ms |
8684 KB |
Output is correct |
4 |
Correct |
28 ms |
8940 KB |
Output is correct |
5 |
Correct |
43 ms |
9836 KB |
Output is correct |
6 |
Correct |
28 ms |
8172 KB |
Output is correct |
7 |
Correct |
9 ms |
5868 KB |
Output is correct |
8 |
Correct |
27 ms |
8172 KB |
Output is correct |
9 |
Correct |
65 ms |
12780 KB |
Output is correct |
10 |
Correct |
37 ms |
9324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5100 KB |
Output is correct |
2 |
Correct |
4 ms |
5100 KB |
Output is correct |
3 |
Correct |
4 ms |
5100 KB |
Output is correct |
4 |
Correct |
4 ms |
5100 KB |
Output is correct |
5 |
Correct |
4 ms |
5100 KB |
Output is correct |
6 |
Correct |
4 ms |
5100 KB |
Output is correct |
7 |
Correct |
4 ms |
5100 KB |
Output is correct |
8 |
Correct |
4 ms |
5100 KB |
Output is correct |
9 |
Correct |
4 ms |
5100 KB |
Output is correct |
10 |
Correct |
4 ms |
5100 KB |
Output is correct |
11 |
Correct |
4 ms |
5100 KB |
Output is correct |
12 |
Correct |
4 ms |
5148 KB |
Output is correct |
13 |
Correct |
4 ms |
5100 KB |
Output is correct |
14 |
Correct |
4 ms |
5100 KB |
Output is correct |
15 |
Correct |
5 ms |
5100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5100 KB |
Output is correct |
2 |
Correct |
4 ms |
5100 KB |
Output is correct |
3 |
Correct |
4 ms |
5100 KB |
Output is correct |
4 |
Correct |
4 ms |
5100 KB |
Output is correct |
5 |
Correct |
4 ms |
5100 KB |
Output is correct |
6 |
Correct |
4 ms |
5100 KB |
Output is correct |
7 |
Correct |
4 ms |
5100 KB |
Output is correct |
8 |
Correct |
4 ms |
5100 KB |
Output is correct |
9 |
Correct |
4 ms |
5100 KB |
Output is correct |
10 |
Correct |
4 ms |
5100 KB |
Output is correct |
11 |
Correct |
4 ms |
5100 KB |
Output is correct |
12 |
Correct |
4 ms |
5148 KB |
Output is correct |
13 |
Correct |
4 ms |
5100 KB |
Output is correct |
14 |
Correct |
4 ms |
5100 KB |
Output is correct |
15 |
Correct |
5 ms |
5100 KB |
Output is correct |
16 |
Correct |
22 ms |
7532 KB |
Output is correct |
17 |
Correct |
47 ms |
12396 KB |
Output is correct |
18 |
Correct |
49 ms |
12780 KB |
Output is correct |
19 |
Correct |
116 ms |
12344 KB |
Output is correct |
20 |
Correct |
115 ms |
12652 KB |
Output is correct |
21 |
Correct |
50 ms |
12268 KB |
Output is correct |
22 |
Correct |
4 ms |
5100 KB |
Output is correct |
23 |
Correct |
28 ms |
8724 KB |
Output is correct |
24 |
Correct |
46 ms |
12524 KB |
Output is correct |
25 |
Correct |
9 ms |
5868 KB |
Output is correct |
26 |
Correct |
31 ms |
9836 KB |
Output is correct |
27 |
Correct |
40 ms |
11244 KB |
Output is correct |
28 |
Correct |
48 ms |
12524 KB |
Output is correct |
29 |
Correct |
18 ms |
8172 KB |
Output is correct |
30 |
Correct |
7 ms |
5356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
10476 KB |
Output is correct |
2 |
Correct |
14 ms |
6508 KB |
Output is correct |
3 |
Correct |
39 ms |
8684 KB |
Output is correct |
4 |
Correct |
28 ms |
8940 KB |
Output is correct |
5 |
Correct |
43 ms |
9836 KB |
Output is correct |
6 |
Correct |
28 ms |
8172 KB |
Output is correct |
7 |
Correct |
9 ms |
5868 KB |
Output is correct |
8 |
Correct |
27 ms |
8172 KB |
Output is correct |
9 |
Correct |
65 ms |
12780 KB |
Output is correct |
10 |
Correct |
37 ms |
9324 KB |
Output is correct |
11 |
Correct |
4 ms |
5100 KB |
Output is correct |
12 |
Correct |
4 ms |
5100 KB |
Output is correct |
13 |
Correct |
4 ms |
5100 KB |
Output is correct |
14 |
Correct |
4 ms |
5100 KB |
Output is correct |
15 |
Correct |
4 ms |
5100 KB |
Output is correct |
16 |
Correct |
4 ms |
5100 KB |
Output is correct |
17 |
Correct |
4 ms |
5100 KB |
Output is correct |
18 |
Correct |
4 ms |
5100 KB |
Output is correct |
19 |
Correct |
4 ms |
5100 KB |
Output is correct |
20 |
Correct |
4 ms |
5100 KB |
Output is correct |
21 |
Correct |
4 ms |
5100 KB |
Output is correct |
22 |
Correct |
4 ms |
5148 KB |
Output is correct |
23 |
Correct |
4 ms |
5100 KB |
Output is correct |
24 |
Correct |
4 ms |
5100 KB |
Output is correct |
25 |
Correct |
5 ms |
5100 KB |
Output is correct |
26 |
Correct |
22 ms |
7532 KB |
Output is correct |
27 |
Correct |
47 ms |
12396 KB |
Output is correct |
28 |
Correct |
49 ms |
12780 KB |
Output is correct |
29 |
Correct |
116 ms |
12344 KB |
Output is correct |
30 |
Correct |
115 ms |
12652 KB |
Output is correct |
31 |
Correct |
50 ms |
12268 KB |
Output is correct |
32 |
Correct |
4 ms |
5100 KB |
Output is correct |
33 |
Correct |
28 ms |
8724 KB |
Output is correct |
34 |
Correct |
46 ms |
12524 KB |
Output is correct |
35 |
Correct |
9 ms |
5868 KB |
Output is correct |
36 |
Correct |
31 ms |
9836 KB |
Output is correct |
37 |
Correct |
40 ms |
11244 KB |
Output is correct |
38 |
Correct |
48 ms |
12524 KB |
Output is correct |
39 |
Correct |
18 ms |
8172 KB |
Output is correct |
40 |
Correct |
7 ms |
5356 KB |
Output is correct |
41 |
Correct |
221 ms |
12364 KB |
Output is correct |
42 |
Correct |
106 ms |
13228 KB |
Output is correct |
43 |
Correct |
163 ms |
12492 KB |
Output is correct |
44 |
Correct |
100 ms |
13164 KB |
Output is correct |
45 |
Correct |
94 ms |
13580 KB |
Output is correct |
46 |
Correct |
247 ms |
13272 KB |
Output is correct |
47 |
Correct |
80 ms |
13036 KB |
Output is correct |
48 |
Correct |
119 ms |
13420 KB |
Output is correct |
49 |
Correct |
93 ms |
13420 KB |
Output is correct |
50 |
Correct |
876 ms |
14160 KB |
Output is correct |
51 |
Correct |
897 ms |
14764 KB |
Output is correct |
52 |
Correct |
876 ms |
14364 KB |
Output is correct |
53 |
Correct |
867 ms |
15100 KB |
Output is correct |
54 |
Correct |
764 ms |
14572 KB |
Output is correct |
55 |
Correct |
862 ms |
15520 KB |
Output is correct |
56 |
Correct |
822 ms |
14464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5100 KB |
Output is correct |
2 |
Correct |
5 ms |
5100 KB |
Output is correct |
3 |
Correct |
4 ms |
5100 KB |
Output is correct |
4 |
Correct |
4 ms |
5100 KB |
Output is correct |
5 |
Correct |
4 ms |
5100 KB |
Output is correct |
6 |
Correct |
4 ms |
5100 KB |
Output is correct |
7 |
Correct |
4 ms |
5100 KB |
Output is correct |
8 |
Correct |
4 ms |
5100 KB |
Output is correct |
9 |
Correct |
48 ms |
10476 KB |
Output is correct |
10 |
Correct |
14 ms |
6508 KB |
Output is correct |
11 |
Correct |
39 ms |
8684 KB |
Output is correct |
12 |
Correct |
28 ms |
8940 KB |
Output is correct |
13 |
Correct |
43 ms |
9836 KB |
Output is correct |
14 |
Correct |
28 ms |
8172 KB |
Output is correct |
15 |
Correct |
9 ms |
5868 KB |
Output is correct |
16 |
Correct |
27 ms |
8172 KB |
Output is correct |
17 |
Correct |
65 ms |
12780 KB |
Output is correct |
18 |
Correct |
37 ms |
9324 KB |
Output is correct |
19 |
Correct |
4 ms |
5100 KB |
Output is correct |
20 |
Correct |
4 ms |
5100 KB |
Output is correct |
21 |
Correct |
4 ms |
5100 KB |
Output is correct |
22 |
Correct |
4 ms |
5100 KB |
Output is correct |
23 |
Correct |
4 ms |
5100 KB |
Output is correct |
24 |
Correct |
4 ms |
5100 KB |
Output is correct |
25 |
Correct |
4 ms |
5100 KB |
Output is correct |
26 |
Correct |
4 ms |
5100 KB |
Output is correct |
27 |
Correct |
4 ms |
5100 KB |
Output is correct |
28 |
Correct |
4 ms |
5100 KB |
Output is correct |
29 |
Correct |
4 ms |
5100 KB |
Output is correct |
30 |
Correct |
4 ms |
5148 KB |
Output is correct |
31 |
Correct |
4 ms |
5100 KB |
Output is correct |
32 |
Correct |
4 ms |
5100 KB |
Output is correct |
33 |
Correct |
5 ms |
5100 KB |
Output is correct |
34 |
Correct |
22 ms |
7532 KB |
Output is correct |
35 |
Correct |
47 ms |
12396 KB |
Output is correct |
36 |
Correct |
49 ms |
12780 KB |
Output is correct |
37 |
Correct |
116 ms |
12344 KB |
Output is correct |
38 |
Correct |
115 ms |
12652 KB |
Output is correct |
39 |
Correct |
50 ms |
12268 KB |
Output is correct |
40 |
Correct |
4 ms |
5100 KB |
Output is correct |
41 |
Correct |
28 ms |
8724 KB |
Output is correct |
42 |
Correct |
46 ms |
12524 KB |
Output is correct |
43 |
Correct |
9 ms |
5868 KB |
Output is correct |
44 |
Correct |
31 ms |
9836 KB |
Output is correct |
45 |
Correct |
40 ms |
11244 KB |
Output is correct |
46 |
Correct |
48 ms |
12524 KB |
Output is correct |
47 |
Correct |
18 ms |
8172 KB |
Output is correct |
48 |
Correct |
7 ms |
5356 KB |
Output is correct |
49 |
Correct |
221 ms |
12364 KB |
Output is correct |
50 |
Correct |
106 ms |
13228 KB |
Output is correct |
51 |
Correct |
163 ms |
12492 KB |
Output is correct |
52 |
Correct |
100 ms |
13164 KB |
Output is correct |
53 |
Correct |
94 ms |
13580 KB |
Output is correct |
54 |
Correct |
247 ms |
13272 KB |
Output is correct |
55 |
Correct |
80 ms |
13036 KB |
Output is correct |
56 |
Correct |
119 ms |
13420 KB |
Output is correct |
57 |
Correct |
93 ms |
13420 KB |
Output is correct |
58 |
Correct |
876 ms |
14160 KB |
Output is correct |
59 |
Correct |
897 ms |
14764 KB |
Output is correct |
60 |
Correct |
876 ms |
14364 KB |
Output is correct |
61 |
Correct |
867 ms |
15100 KB |
Output is correct |
62 |
Correct |
764 ms |
14572 KB |
Output is correct |
63 |
Correct |
862 ms |
15520 KB |
Output is correct |
64 |
Correct |
822 ms |
14464 KB |
Output is correct |
65 |
Correct |
4 ms |
5100 KB |
Output is correct |
66 |
Correct |
4 ms |
5100 KB |
Output is correct |
67 |
Correct |
819 ms |
14720 KB |
Output is correct |
68 |
Correct |
881 ms |
14956 KB |
Output is correct |
69 |
Correct |
634 ms |
13420 KB |
Output is correct |
70 |
Correct |
634 ms |
14444 KB |
Output is correct |
71 |
Correct |
719 ms |
14352 KB |
Output is correct |
72 |
Correct |
658 ms |
14124 KB |
Output is correct |
73 |
Correct |
757 ms |
14060 KB |
Output is correct |
74 |
Correct |
919 ms |
14860 KB |
Output is correct |
75 |
Correct |
733 ms |
14288 KB |
Output is correct |
76 |
Correct |
777 ms |
14956 KB |
Output is correct |
77 |
Correct |
147 ms |
15340 KB |
Output is correct |
78 |
Correct |
77 ms |
14316 KB |
Output is correct |
79 |
Correct |
127 ms |
13932 KB |
Output is correct |
80 |
Correct |
139 ms |
14392 KB |
Output is correct |
81 |
Correct |
113 ms |
13676 KB |
Output is correct |
82 |
Correct |
109 ms |
15084 KB |
Output is correct |
83 |
Correct |
87 ms |
14060 KB |
Output is correct |
84 |
Correct |
463 ms |
15212 KB |
Output is correct |
85 |
Correct |
1016 ms |
15596 KB |
Output is correct |
86 |
Correct |
73 ms |
5100 KB |
Output is correct |
87 |
Correct |
75 ms |
5100 KB |
Output is correct |
88 |
Correct |
813 ms |
15596 KB |
Output is correct |
89 |
Correct |
184 ms |
7148 KB |
Output is correct |
90 |
Correct |
73 ms |
5100 KB |
Output is correct |