Submission #334487

# Submission time Handle Problem Language Result Execution time Memory
334487 2020-12-09T08:47:50 Z juggernaut Chessboard (IZhO18_chessboard) C++14
100 / 100
236 ms 6892 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Rect{
    ll x,y,x2,y2;
    void _minus(){
        x--,y--,x2--,y2--;
    }
}rect[100005];
ll n,m,pref_bl[100005],pref_wh[100005];
ll range_bl(ll l,ll r){
    if(l)return pref_bl[r]-pref_bl[l-1];
    return pref_bl[r];
}
ll range_wh(ll l,ll r){
    if(l)return pref_wh[r]-pref_wh[l-1];
    return pref_wh[r];
}
ll calc_bl(ll x,ll y,ll x2,ll y2){
    ll ans=0;
    ans+=range_bl(x,x2)*range_bl(y,y2);
    ans+=range_wh(x,x2)*range_wh(y,y2);
    return ans;
}
ll calc_wh(ll x,ll y,ll x2,ll y2){
    ll ans=0;
    ans=(x2-x+1)*(y2-y+1)-calc_bl(x,y,x2,y2);
    return ans;
}
ll solve(ll side){
    ll sz=n/side;
    ll wh=0,bl=side*side*((sz*sz+1)>>1);
    pref_bl[0]=1;
    pref_wh[0]=0;
    for(ll i=1;i<n;i++)
        pref_wh[i]=pref_wh[i-1]+((i/side)&1),pref_bl[i]=i+1-pref_wh[i];
    for(ll i=0;i<m;i++){
        wh+=calc_wh(rect[i].x,rect[i].y,rect[i].x2,rect[i].y2);
        bl-=calc_bl(rect[i].x,rect[i].y,rect[i].x2,rect[i].y2);
    }
    return min(wh+bl,n*n-wh-bl);
}
int main(){
    scanf("%lld%lld",&n,&m);
    for(ll i=0;i<m;i++)scanf("%lld%lld%lld%lld",&rect[i].x,&rect[i].y,&rect[i].x2,&rect[i].y2),rect[i]._minus();
    ll res=solve(1);
    for(ll i=2;i*i<=n;i++)if(n%i==0)res=min(res,min(solve(i),solve(n/i)));
    printf("%lld",res);
}

Compilation message

chessboard.cpp: In function 'int main()':
chessboard.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   44 |     scanf("%lld%lld",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
chessboard.cpp:45:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   45 |     for(ll i=0;i<m;i++)scanf("%lld%lld%lld%lld",&rect[i].x,&rect[i].y,&rect[i].x2,&rect[i].y2),rect[i]._minus();
      |                        ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 3308 KB Output is correct
2 Correct 7 ms 1004 KB Output is correct
3 Correct 17 ms 2924 KB Output is correct
4 Correct 17 ms 1772 KB Output is correct
5 Correct 22 ms 2924 KB Output is correct
6 Correct 14 ms 2156 KB Output is correct
7 Correct 4 ms 876 KB Output is correct
8 Correct 18 ms 2156 KB Output is correct
9 Correct 37 ms 3580 KB Output is correct
10 Correct 20 ms 2540 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 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 384 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 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 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 384 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 10 ms 1260 KB Output is correct
17 Correct 28 ms 2924 KB Output is correct
18 Correct 34 ms 3436 KB Output is correct
19 Correct 40 ms 3180 KB Output is correct
20 Correct 44 ms 3436 KB Output is correct
21 Correct 27 ms 2924 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 15 ms 1664 KB Output is correct
24 Correct 33 ms 3180 KB Output is correct
25 Correct 4 ms 620 KB Output is correct
26 Correct 19 ms 2156 KB Output is correct
27 Correct 24 ms 2412 KB Output is correct
28 Correct 32 ms 3308 KB Output is correct
29 Correct 11 ms 1388 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 3308 KB Output is correct
2 Correct 7 ms 1004 KB Output is correct
3 Correct 17 ms 2924 KB Output is correct
4 Correct 17 ms 1772 KB Output is correct
5 Correct 22 ms 2924 KB Output is correct
6 Correct 14 ms 2156 KB Output is correct
7 Correct 4 ms 876 KB Output is correct
8 Correct 18 ms 2156 KB Output is correct
9 Correct 37 ms 3580 KB Output is correct
10 Correct 20 ms 2540 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 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 384 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 10 ms 1260 KB Output is correct
27 Correct 28 ms 2924 KB Output is correct
28 Correct 34 ms 3436 KB Output is correct
29 Correct 40 ms 3180 KB Output is correct
30 Correct 44 ms 3436 KB Output is correct
31 Correct 27 ms 2924 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 15 ms 1664 KB Output is correct
34 Correct 33 ms 3180 KB Output is correct
35 Correct 4 ms 620 KB Output is correct
36 Correct 19 ms 2156 KB Output is correct
37 Correct 24 ms 2412 KB Output is correct
38 Correct 32 ms 3308 KB Output is correct
39 Correct 11 ms 1388 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 66 ms 4460 KB Output is correct
42 Correct 42 ms 4844 KB Output is correct
43 Correct 48 ms 4460 KB Output is correct
44 Correct 39 ms 4716 KB Output is correct
45 Correct 39 ms 4972 KB Output is correct
46 Correct 74 ms 4844 KB Output is correct
47 Correct 47 ms 4588 KB Output is correct
48 Correct 55 ms 4736 KB Output is correct
49 Correct 36 ms 4460 KB Output is correct
50 Correct 217 ms 4460 KB Output is correct
51 Correct 233 ms 4716 KB Output is correct
52 Correct 220 ms 4460 KB Output is correct
53 Correct 227 ms 4588 KB Output is correct
54 Correct 219 ms 4588 KB Output is correct
55 Correct 236 ms 4844 KB Output is correct
56 Correct 214 ms 4332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 25 ms 3308 KB Output is correct
10 Correct 7 ms 1004 KB Output is correct
11 Correct 17 ms 2924 KB Output is correct
12 Correct 17 ms 1772 KB Output is correct
13 Correct 22 ms 2924 KB Output is correct
14 Correct 14 ms 2156 KB Output is correct
15 Correct 4 ms 876 KB Output is correct
16 Correct 18 ms 2156 KB Output is correct
17 Correct 37 ms 3580 KB Output is correct
18 Correct 20 ms 2540 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 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 384 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 10 ms 1260 KB Output is correct
35 Correct 28 ms 2924 KB Output is correct
36 Correct 34 ms 3436 KB Output is correct
37 Correct 40 ms 3180 KB Output is correct
38 Correct 44 ms 3436 KB Output is correct
39 Correct 27 ms 2924 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 15 ms 1664 KB Output is correct
42 Correct 33 ms 3180 KB Output is correct
43 Correct 4 ms 620 KB Output is correct
44 Correct 19 ms 2156 KB Output is correct
45 Correct 24 ms 2412 KB Output is correct
46 Correct 32 ms 3308 KB Output is correct
47 Correct 11 ms 1388 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 66 ms 4460 KB Output is correct
50 Correct 42 ms 4844 KB Output is correct
51 Correct 48 ms 4460 KB Output is correct
52 Correct 39 ms 4716 KB Output is correct
53 Correct 39 ms 4972 KB Output is correct
54 Correct 74 ms 4844 KB Output is correct
55 Correct 47 ms 4588 KB Output is correct
56 Correct 55 ms 4736 KB Output is correct
57 Correct 36 ms 4460 KB Output is correct
58 Correct 217 ms 4460 KB Output is correct
59 Correct 233 ms 4716 KB Output is correct
60 Correct 220 ms 4460 KB Output is correct
61 Correct 227 ms 4588 KB Output is correct
62 Correct 219 ms 4588 KB Output is correct
63 Correct 236 ms 4844 KB Output is correct
64 Correct 214 ms 4332 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 1 ms 364 KB Output is correct
67 Correct 224 ms 4588 KB Output is correct
68 Correct 228 ms 6508 KB Output is correct
69 Correct 204 ms 6124 KB Output is correct
70 Correct 203 ms 6508 KB Output is correct
71 Correct 205 ms 6380 KB Output is correct
72 Correct 208 ms 6252 KB Output is correct
73 Correct 210 ms 6380 KB Output is correct
74 Correct 223 ms 6508 KB Output is correct
75 Correct 209 ms 6380 KB Output is correct
76 Correct 224 ms 6520 KB Output is correct
77 Correct 63 ms 6892 KB Output is correct
78 Correct 41 ms 6636 KB Output is correct
79 Correct 52 ms 6508 KB Output is correct
80 Correct 52 ms 6636 KB Output is correct
81 Correct 51 ms 6380 KB Output is correct
82 Correct 48 ms 6764 KB Output is correct
83 Correct 41 ms 6508 KB Output is correct
84 Correct 154 ms 6764 KB Output is correct
85 Correct 233 ms 6636 KB Output is correct
86 Correct 69 ms 1644 KB Output is correct
87 Correct 69 ms 1644 KB Output is correct
88 Correct 229 ms 6508 KB Output is correct
89 Correct 99 ms 2796 KB Output is correct
90 Correct 69 ms 1644 KB Output is correct