#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(n) rep1(i,n)
#define rep1(i,n) rep2(i,0,n)
#define rep2(i,a,b) for(int i=a; i<b; ++i)
#define rep3(i,a,b) for(int i=a; i>=b; --i)
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define pow2(x) (1ll<<(x))
#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << ' ' << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(T && x){cerr << x << endl;}
template<typename T, typename ...S> void _do(T && x, S&&... y){cerr << x << ' ',_do(y...);}
#else
#define bug(...) 826
#endif
const int maxn=100005;
const int mod=1000000007;
#define y1 hhhhaura_TOI_2J
int n,k,x1[maxn],x2[maxn],y1[maxn],y2[maxn],area,ans=1e18;
int calc1(int t, int id){
return ((x1[id]/t)+(y1[id]/t))&1;
}
int calc2(int t, int id){
return !(((x1[id]/t)+(y1[id]/t))&1);
}
signed main(){
ios_base::sync_with_stdio(0),cin.tie(0);
#ifdef i_am_noob
freopen("input1.txt","r",stdin);
freopen("output1.txt","w",stdout);
freopen("output2.txt","w",stderr);
#endif
cin >> n >> k;
rep(k) cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
rep(k) x1[i]--,y1[i]--,x2[i]--,y2[i]--;
rep(k) area+=(x2[i]-x1[i]+1)*(y2[i]-y1[i]+1);
bug(area);
rep2(i,1,n) if(n%i==0){
int val=0;
rep1(j,k) val+=calc1(i,j);
//area-val good
//cnt(black)-(area-val)
bug(val);
val+=((n/i)&1?((n/i)*(n/i)+1)/2*i*i:(n/i)*(n/i)/2*i*i)-area+val;
ans=min(ans,val);
bug(val);
val=0;
rep1(j,k) val+=calc2(i,j);
bug(val);
val+=(n/i)*(n/i)/2*i*i-area+val;
ans=min(ans,val);
bug(val);
}
cout << ans << "\n";
}
Compilation message
chessboard.cpp: In function 'int main()':
chessboard.cpp:18:18: warning: statement has no effect [-Wunused-value]
18 | #define bug(...) 826
| ^~~
chessboard.cpp:46:5: note: in expansion of macro 'bug'
46 | bug(area);
| ^~~
chessboard.cpp:18:18: warning: statement has no effect [-Wunused-value]
18 | #define bug(...) 826
| ^~~
chessboard.cpp:52:9: note: in expansion of macro 'bug'
52 | bug(val);
| ^~~
chessboard.cpp:18:18: warning: statement has no effect [-Wunused-value]
18 | #define bug(...) 826
| ^~~
chessboard.cpp:55:9: note: in expansion of macro 'bug'
55 | bug(val);
| ^~~
chessboard.cpp:18:18: warning: statement has no effect [-Wunused-value]
18 | #define bug(...) 826
| ^~~
chessboard.cpp:58:9: note: in expansion of macro 'bug'
58 | bug(val);
| ^~~
chessboard.cpp:18:18: warning: statement has no effect [-Wunused-value]
18 | #define bug(...) 826
| ^~~
chessboard.cpp:61:9: note: in expansion of macro 'bug'
61 | bug(val);
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
2924 KB |
Output is correct |
2 |
Correct |
9 ms |
1260 KB |
Output is correct |
3 |
Correct |
17 ms |
2416 KB |
Output is correct |
4 |
Correct |
19 ms |
2540 KB |
Output is correct |
5 |
Correct |
26 ms |
2796 KB |
Output is correct |
6 |
Correct |
18 ms |
2284 KB |
Output is correct |
7 |
Correct |
4 ms |
748 KB |
Output is correct |
8 |
Correct |
16 ms |
2156 KB |
Output is correct |
9 |
Correct |
53 ms |
3948 KB |
Output is correct |
10 |
Correct |
22 ms |
2700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
396 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
396 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
12 ms |
1600 KB |
Output is correct |
17 |
Correct |
36 ms |
3692 KB |
Output is correct |
18 |
Correct |
45 ms |
4204 KB |
Output is correct |
19 |
Correct |
84 ms |
3820 KB |
Output is correct |
20 |
Correct |
115 ms |
4204 KB |
Output is correct |
21 |
Correct |
29 ms |
3692 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
22 ms |
2412 KB |
Output is correct |
24 |
Correct |
37 ms |
3948 KB |
Output is correct |
25 |
Correct |
5 ms |
748 KB |
Output is correct |
26 |
Correct |
23 ms |
2924 KB |
Output is correct |
27 |
Correct |
30 ms |
3308 KB |
Output is correct |
28 |
Correct |
38 ms |
4076 KB |
Output is correct |
29 |
Correct |
12 ms |
1900 KB |
Output is correct |
30 |
Correct |
2 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
2924 KB |
Output is correct |
2 |
Correct |
9 ms |
1260 KB |
Output is correct |
3 |
Correct |
17 ms |
2416 KB |
Output is correct |
4 |
Correct |
19 ms |
2540 KB |
Output is correct |
5 |
Correct |
26 ms |
2796 KB |
Output is correct |
6 |
Correct |
18 ms |
2284 KB |
Output is correct |
7 |
Correct |
4 ms |
748 KB |
Output is correct |
8 |
Correct |
16 ms |
2156 KB |
Output is correct |
9 |
Correct |
53 ms |
3948 KB |
Output is correct |
10 |
Correct |
22 ms |
2700 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
396 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
12 ms |
1600 KB |
Output is correct |
27 |
Correct |
36 ms |
3692 KB |
Output is correct |
28 |
Correct |
45 ms |
4204 KB |
Output is correct |
29 |
Correct |
84 ms |
3820 KB |
Output is correct |
30 |
Correct |
115 ms |
4204 KB |
Output is correct |
31 |
Correct |
29 ms |
3692 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
22 ms |
2412 KB |
Output is correct |
34 |
Correct |
37 ms |
3948 KB |
Output is correct |
35 |
Correct |
5 ms |
748 KB |
Output is correct |
36 |
Correct |
23 ms |
2924 KB |
Output is correct |
37 |
Correct |
30 ms |
3308 KB |
Output is correct |
38 |
Correct |
38 ms |
4076 KB |
Output is correct |
39 |
Correct |
12 ms |
1900 KB |
Output is correct |
40 |
Correct |
2 ms |
492 KB |
Output is correct |
41 |
Correct |
83 ms |
3692 KB |
Output is correct |
42 |
Correct |
43 ms |
4076 KB |
Output is correct |
43 |
Correct |
56 ms |
3692 KB |
Output is correct |
44 |
Correct |
44 ms |
3948 KB |
Output is correct |
45 |
Correct |
43 ms |
4204 KB |
Output is correct |
46 |
Correct |
90 ms |
4000 KB |
Output is correct |
47 |
Correct |
35 ms |
3820 KB |
Output is correct |
48 |
Correct |
49 ms |
3820 KB |
Output is correct |
49 |
Correct |
74 ms |
3692 KB |
Output is correct |
50 |
Correct |
358 ms |
4076 KB |
Output is correct |
51 |
Correct |
374 ms |
4332 KB |
Output is correct |
52 |
Correct |
340 ms |
4076 KB |
Output is correct |
53 |
Correct |
350 ms |
4204 KB |
Output is correct |
54 |
Correct |
327 ms |
3948 KB |
Output is correct |
55 |
Correct |
363 ms |
4332 KB |
Output is correct |
56 |
Correct |
315 ms |
3820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
33 ms |
2924 KB |
Output is correct |
10 |
Correct |
9 ms |
1260 KB |
Output is correct |
11 |
Correct |
17 ms |
2416 KB |
Output is correct |
12 |
Correct |
19 ms |
2540 KB |
Output is correct |
13 |
Correct |
26 ms |
2796 KB |
Output is correct |
14 |
Correct |
18 ms |
2284 KB |
Output is correct |
15 |
Correct |
4 ms |
748 KB |
Output is correct |
16 |
Correct |
16 ms |
2156 KB |
Output is correct |
17 |
Correct |
53 ms |
3948 KB |
Output is correct |
18 |
Correct |
22 ms |
2700 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
2 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
396 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
12 ms |
1600 KB |
Output is correct |
35 |
Correct |
36 ms |
3692 KB |
Output is correct |
36 |
Correct |
45 ms |
4204 KB |
Output is correct |
37 |
Correct |
84 ms |
3820 KB |
Output is correct |
38 |
Correct |
115 ms |
4204 KB |
Output is correct |
39 |
Correct |
29 ms |
3692 KB |
Output is correct |
40 |
Correct |
1 ms |
364 KB |
Output is correct |
41 |
Correct |
22 ms |
2412 KB |
Output is correct |
42 |
Correct |
37 ms |
3948 KB |
Output is correct |
43 |
Correct |
5 ms |
748 KB |
Output is correct |
44 |
Correct |
23 ms |
2924 KB |
Output is correct |
45 |
Correct |
30 ms |
3308 KB |
Output is correct |
46 |
Correct |
38 ms |
4076 KB |
Output is correct |
47 |
Correct |
12 ms |
1900 KB |
Output is correct |
48 |
Correct |
2 ms |
492 KB |
Output is correct |
49 |
Correct |
83 ms |
3692 KB |
Output is correct |
50 |
Correct |
43 ms |
4076 KB |
Output is correct |
51 |
Correct |
56 ms |
3692 KB |
Output is correct |
52 |
Correct |
44 ms |
3948 KB |
Output is correct |
53 |
Correct |
43 ms |
4204 KB |
Output is correct |
54 |
Correct |
90 ms |
4000 KB |
Output is correct |
55 |
Correct |
35 ms |
3820 KB |
Output is correct |
56 |
Correct |
49 ms |
3820 KB |
Output is correct |
57 |
Correct |
74 ms |
3692 KB |
Output is correct |
58 |
Correct |
358 ms |
4076 KB |
Output is correct |
59 |
Correct |
374 ms |
4332 KB |
Output is correct |
60 |
Correct |
340 ms |
4076 KB |
Output is correct |
61 |
Correct |
350 ms |
4204 KB |
Output is correct |
62 |
Correct |
327 ms |
3948 KB |
Output is correct |
63 |
Correct |
363 ms |
4332 KB |
Output is correct |
64 |
Correct |
315 ms |
3820 KB |
Output is correct |
65 |
Correct |
1 ms |
364 KB |
Output is correct |
66 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
67 |
Halted |
0 ms |
0 KB |
- |