#include <iostream>
#include <stdio.h>
using namespace std;
const int MAXK=100005;
long long mini[MAXK], maxi[MAXK], minj[MAXK], maxj[MAXK];
long long NumWhite(long long, long long, long long, long long, long long cellLen);
long long FindAns(long long n, long long k, long long cellLen);
int main()
{
long long n, k;
cin>>n>>k;
for (int i=0; i<k; i++)
scanf("%lld%lld%lld%lld", mini+i, minj+i, maxi+i, maxj+i);
long long ans=n*n;
for (int cellLen=1; cellLen*cellLen<=n; cellLen++)
if (n%cellLen==0)
{
ans=min(ans, FindAns(n, k, cellLen));
ans=min(ans, FindAns(n, k, n/cellLen));
}
cout<<ans<<'\n';
char I;
cin >> I;
return 0;
}
long long FindAns(long long n, long long k, long long cellLen)
{
if (cellLen>=n) return n*n;
long long shouldWhite=0, shouldBlack=0, isBlack=0;
for (int i=0; i<k; i++)
{
shouldWhite+=NumWhite(mini[i], minj[i], maxi[i], maxj[i], cellLen);
isBlack+=(maxi[i]-mini[i]+1)*(maxj[i]-minj[i]+1);
}
shouldBlack=(n*n-NumWhite(1, 1, n, n, cellLen))-(isBlack-shouldWhite);
return min(shouldWhite+shouldBlack, n*n-(shouldWhite+shouldBlack));
}
long long NumWhite(long long mini, long long minj, long long maxi, long long maxj, long long len)
{
if (!mini) mini=1;
if (!minj) minj=1;
if (mini==1 && minj==1)
{
long long ans=0, i=maxi, j=maxj;
ans+=len*len*(((i/len)*(j/len)+1)/2);
if ((i/len)%2)
ans+=(i%len)*((j/len)/2)*len;
else
ans+=(i%len)*((j/len+1)/2)*len;
if ((j/len)%2)
ans+=(j%len)*((i/len)/2)*len;
else
ans+=(j%len)*((i/len+1)/2)*len;
if ((i/len)%2==(j/len)%2)
ans+=(i%len)*(j%len);
return ans;
}
return NumWhite(1, 1, maxi, maxj, len)-
NumWhite(1, 1, maxi, minj-1, len)-NumWhite(1, 1, mini-1, maxj, len)+
NumWhite(1, 1, mini-1, minj-1, len);
}
Compilation message
chessboard.cpp: In function 'int main()':
chessboard.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld%lld%lld", mini+i, minj+i, maxi+i, maxj+i);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
252 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
356 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
2552 KB |
Output is correct |
2 |
Correct |
10 ms |
888 KB |
Output is correct |
3 |
Correct |
22 ms |
1784 KB |
Output is correct |
4 |
Correct |
24 ms |
1912 KB |
Output is correct |
5 |
Correct |
29 ms |
2168 KB |
Output is correct |
6 |
Correct |
20 ms |
1528 KB |
Output is correct |
7 |
Correct |
5 ms |
632 KB |
Output is correct |
8 |
Correct |
20 ms |
1572 KB |
Output is correct |
9 |
Correct |
48 ms |
3320 KB |
Output is correct |
10 |
Correct |
29 ms |
2040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
420 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
296 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
1 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
380 KB |
Output is correct |
14 |
Correct |
3 ms |
292 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
420 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
296 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
1 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
380 KB |
Output is correct |
14 |
Correct |
3 ms |
292 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
23 ms |
1272 KB |
Output is correct |
17 |
Correct |
41 ms |
3164 KB |
Output is correct |
18 |
Correct |
76 ms |
3616 KB |
Output is correct |
19 |
Correct |
358 ms |
3320 KB |
Output is correct |
20 |
Correct |
403 ms |
3688 KB |
Output is correct |
21 |
Correct |
40 ms |
3036 KB |
Output is correct |
22 |
Correct |
3 ms |
376 KB |
Output is correct |
23 |
Correct |
55 ms |
1800 KB |
Output is correct |
24 |
Correct |
68 ms |
3264 KB |
Output is correct |
25 |
Correct |
13 ms |
732 KB |
Output is correct |
26 |
Correct |
43 ms |
2296 KB |
Output is correct |
27 |
Correct |
80 ms |
2668 KB |
Output is correct |
28 |
Correct |
70 ms |
3528 KB |
Output is correct |
29 |
Correct |
17 ms |
1404 KB |
Output is correct |
30 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
2552 KB |
Output is correct |
2 |
Correct |
10 ms |
888 KB |
Output is correct |
3 |
Correct |
22 ms |
1784 KB |
Output is correct |
4 |
Correct |
24 ms |
1912 KB |
Output is correct |
5 |
Correct |
29 ms |
2168 KB |
Output is correct |
6 |
Correct |
20 ms |
1528 KB |
Output is correct |
7 |
Correct |
5 ms |
632 KB |
Output is correct |
8 |
Correct |
20 ms |
1572 KB |
Output is correct |
9 |
Correct |
48 ms |
3320 KB |
Output is correct |
10 |
Correct |
29 ms |
2040 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
3 ms |
420 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
296 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
1 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
3 ms |
380 KB |
Output is correct |
24 |
Correct |
3 ms |
292 KB |
Output is correct |
25 |
Correct |
3 ms |
376 KB |
Output is correct |
26 |
Correct |
23 ms |
1272 KB |
Output is correct |
27 |
Correct |
41 ms |
3164 KB |
Output is correct |
28 |
Correct |
76 ms |
3616 KB |
Output is correct |
29 |
Correct |
358 ms |
3320 KB |
Output is correct |
30 |
Correct |
403 ms |
3688 KB |
Output is correct |
31 |
Correct |
40 ms |
3036 KB |
Output is correct |
32 |
Correct |
3 ms |
376 KB |
Output is correct |
33 |
Correct |
55 ms |
1800 KB |
Output is correct |
34 |
Correct |
68 ms |
3264 KB |
Output is correct |
35 |
Correct |
13 ms |
732 KB |
Output is correct |
36 |
Correct |
43 ms |
2296 KB |
Output is correct |
37 |
Correct |
80 ms |
2668 KB |
Output is correct |
38 |
Correct |
70 ms |
3528 KB |
Output is correct |
39 |
Correct |
17 ms |
1404 KB |
Output is correct |
40 |
Correct |
4 ms |
376 KB |
Output is correct |
41 |
Correct |
284 ms |
3016 KB |
Output is correct |
42 |
Correct |
81 ms |
3448 KB |
Output is correct |
43 |
Correct |
155 ms |
3064 KB |
Output is correct |
44 |
Correct |
73 ms |
3320 KB |
Output is correct |
45 |
Correct |
52 ms |
3576 KB |
Output is correct |
46 |
Correct |
322 ms |
3436 KB |
Output is correct |
47 |
Correct |
48 ms |
3192 KB |
Output is correct |
48 |
Correct |
115 ms |
3248 KB |
Output is correct |
49 |
Correct |
70 ms |
3292 KB |
Output is correct |
50 |
Correct |
1617 ms |
3448 KB |
Output is correct |
51 |
Correct |
1674 ms |
3676 KB |
Output is correct |
52 |
Correct |
1550 ms |
3320 KB |
Output is correct |
53 |
Correct |
1686 ms |
3448 KB |
Output is correct |
54 |
Correct |
1521 ms |
3308 KB |
Output is correct |
55 |
Correct |
1709 ms |
3704 KB |
Output is correct |
56 |
Correct |
1505 ms |
3320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
252 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
356 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
252 KB |
Output is correct |
9 |
Correct |
34 ms |
2552 KB |
Output is correct |
10 |
Correct |
10 ms |
888 KB |
Output is correct |
11 |
Correct |
22 ms |
1784 KB |
Output is correct |
12 |
Correct |
24 ms |
1912 KB |
Output is correct |
13 |
Correct |
29 ms |
2168 KB |
Output is correct |
14 |
Correct |
20 ms |
1528 KB |
Output is correct |
15 |
Correct |
5 ms |
632 KB |
Output is correct |
16 |
Correct |
20 ms |
1572 KB |
Output is correct |
17 |
Correct |
48 ms |
3320 KB |
Output is correct |
18 |
Correct |
29 ms |
2040 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
380 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
376 KB |
Output is correct |
23 |
Correct |
3 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
3 ms |
420 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
296 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
1 ms |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
3 ms |
380 KB |
Output is correct |
32 |
Correct |
3 ms |
292 KB |
Output is correct |
33 |
Correct |
3 ms |
376 KB |
Output is correct |
34 |
Correct |
23 ms |
1272 KB |
Output is correct |
35 |
Correct |
41 ms |
3164 KB |
Output is correct |
36 |
Correct |
76 ms |
3616 KB |
Output is correct |
37 |
Correct |
358 ms |
3320 KB |
Output is correct |
38 |
Correct |
403 ms |
3688 KB |
Output is correct |
39 |
Correct |
40 ms |
3036 KB |
Output is correct |
40 |
Correct |
3 ms |
376 KB |
Output is correct |
41 |
Correct |
55 ms |
1800 KB |
Output is correct |
42 |
Correct |
68 ms |
3264 KB |
Output is correct |
43 |
Correct |
13 ms |
732 KB |
Output is correct |
44 |
Correct |
43 ms |
2296 KB |
Output is correct |
45 |
Correct |
80 ms |
2668 KB |
Output is correct |
46 |
Correct |
70 ms |
3528 KB |
Output is correct |
47 |
Correct |
17 ms |
1404 KB |
Output is correct |
48 |
Correct |
4 ms |
376 KB |
Output is correct |
49 |
Correct |
284 ms |
3016 KB |
Output is correct |
50 |
Correct |
81 ms |
3448 KB |
Output is correct |
51 |
Correct |
155 ms |
3064 KB |
Output is correct |
52 |
Correct |
73 ms |
3320 KB |
Output is correct |
53 |
Correct |
52 ms |
3576 KB |
Output is correct |
54 |
Correct |
322 ms |
3436 KB |
Output is correct |
55 |
Correct |
48 ms |
3192 KB |
Output is correct |
56 |
Correct |
115 ms |
3248 KB |
Output is correct |
57 |
Correct |
70 ms |
3292 KB |
Output is correct |
58 |
Correct |
1617 ms |
3448 KB |
Output is correct |
59 |
Correct |
1674 ms |
3676 KB |
Output is correct |
60 |
Correct |
1550 ms |
3320 KB |
Output is correct |
61 |
Correct |
1686 ms |
3448 KB |
Output is correct |
62 |
Correct |
1521 ms |
3308 KB |
Output is correct |
63 |
Correct |
1709 ms |
3704 KB |
Output is correct |
64 |
Correct |
1505 ms |
3320 KB |
Output is correct |
65 |
Correct |
2 ms |
376 KB |
Output is correct |
66 |
Correct |
2 ms |
376 KB |
Output is correct |
67 |
Correct |
1634 ms |
3660 KB |
Output is correct |
68 |
Correct |
1623 ms |
3704 KB |
Output is correct |
69 |
Correct |
1420 ms |
3192 KB |
Output is correct |
70 |
Correct |
1577 ms |
3448 KB |
Output is correct |
71 |
Correct |
1563 ms |
3448 KB |
Output is correct |
72 |
Correct |
1499 ms |
3444 KB |
Output is correct |
73 |
Correct |
1503 ms |
3424 KB |
Output is correct |
74 |
Correct |
1604 ms |
3676 KB |
Output is correct |
75 |
Correct |
1504 ms |
3576 KB |
Output is correct |
76 |
Correct |
1634 ms |
3576 KB |
Output is correct |
77 |
Correct |
236 ms |
3704 KB |
Output is correct |
78 |
Correct |
73 ms |
3448 KB |
Output is correct |
79 |
Correct |
158 ms |
3320 KB |
Output is correct |
80 |
Correct |
165 ms |
3448 KB |
Output is correct |
81 |
Correct |
153 ms |
3228 KB |
Output is correct |
82 |
Correct |
124 ms |
3576 KB |
Output is correct |
83 |
Correct |
92 ms |
3340 KB |
Output is correct |
84 |
Correct |
1089 ms |
3704 KB |
Output is correct |
85 |
Correct |
1803 ms |
3772 KB |
Output is correct |
86 |
Correct |
3 ms |
376 KB |
Output is correct |
87 |
Correct |
2 ms |
376 KB |
Output is correct |
88 |
Correct |
1868 ms |
3960 KB |
Output is correct |
89 |
Correct |
320 ms |
1400 KB |
Output is correct |
90 |
Correct |
2 ms |
376 KB |
Output is correct |