Submission #347023

# Submission time Handle Problem Language Result Execution time Memory
347023 2021-01-11T14:25:27 Z andrii Chessboard (IZhO18_chessboard) C++14
70 / 100
966 ms 15856 KB
// -- //
#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[be&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[be&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;
      |          ^~
# Verdict Execution time Memory 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 5 ms 5228 KB Output is correct
7 Correct 4 ms 5100 KB Output is correct
8 Correct 4 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 11884 KB Output is correct
2 Correct 14 ms 7032 KB Output is correct
3 Correct 36 ms 9452 KB Output is correct
4 Correct 27 ms 9708 KB Output is correct
5 Correct 45 ms 10988 KB Output is correct
6 Correct 29 ms 8812 KB Output is correct
7 Correct 9 ms 6016 KB Output is correct
8 Correct 37 ms 8940 KB Output is correct
9 Correct 73 ms 14572 KB Output is correct
10 Correct 39 ms 10476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5116 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 5228 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 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
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5116 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 5228 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 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 17 ms 7660 KB Output is correct
17 Correct 40 ms 13420 KB Output is correct
18 Correct 52 ms 14336 KB Output is correct
19 Correct 99 ms 13420 KB Output is correct
20 Correct 107 ms 14060 KB Output is correct
21 Correct 38 ms 13292 KB Output is correct
22 Correct 4 ms 5100 KB Output is correct
23 Correct 28 ms 9196 KB Output is correct
24 Correct 50 ms 13676 KB Output is correct
25 Correct 10 ms 5996 KB Output is correct
26 Correct 30 ms 10476 KB Output is correct
27 Correct 39 ms 12044 KB Output is correct
28 Correct 48 ms 13804 KB Output is correct
29 Correct 18 ms 8428 KB Output is correct
30 Correct 5 ms 5356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 11884 KB Output is correct
2 Correct 14 ms 7032 KB Output is correct
3 Correct 36 ms 9452 KB Output is correct
4 Correct 27 ms 9708 KB Output is correct
5 Correct 45 ms 10988 KB Output is correct
6 Correct 29 ms 8812 KB Output is correct
7 Correct 9 ms 6016 KB Output is correct
8 Correct 37 ms 8940 KB Output is correct
9 Correct 73 ms 14572 KB Output is correct
10 Correct 39 ms 10476 KB Output is correct
11 Correct 4 ms 5100 KB Output is correct
12 Correct 4 ms 5116 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 5228 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 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 17 ms 7660 KB Output is correct
27 Correct 40 ms 13420 KB Output is correct
28 Correct 52 ms 14336 KB Output is correct
29 Correct 99 ms 13420 KB Output is correct
30 Correct 107 ms 14060 KB Output is correct
31 Correct 38 ms 13292 KB Output is correct
32 Correct 4 ms 5100 KB Output is correct
33 Correct 28 ms 9196 KB Output is correct
34 Correct 50 ms 13676 KB Output is correct
35 Correct 10 ms 5996 KB Output is correct
36 Correct 30 ms 10476 KB Output is correct
37 Correct 39 ms 12044 KB Output is correct
38 Correct 48 ms 13804 KB Output is correct
39 Correct 18 ms 8428 KB Output is correct
40 Correct 5 ms 5356 KB Output is correct
41 Correct 201 ms 14060 KB Output is correct
42 Correct 98 ms 15468 KB Output is correct
43 Correct 153 ms 14188 KB Output is correct
44 Correct 92 ms 14956 KB Output is correct
45 Correct 85 ms 15724 KB Output is correct
46 Correct 235 ms 15308 KB Output is correct
47 Correct 73 ms 14444 KB Output is correct
48 Correct 114 ms 14700 KB Output is correct
49 Correct 84 ms 14188 KB Output is correct
50 Correct 887 ms 14956 KB Output is correct
51 Correct 891 ms 15540 KB Output is correct
52 Correct 781 ms 14828 KB Output is correct
53 Correct 930 ms 15596 KB Output is correct
54 Correct 836 ms 14860 KB Output is correct
55 Correct 966 ms 15856 KB Output is correct
56 Correct 793 ms 14444 KB Output is correct
# Verdict Execution time Memory 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 5 ms 5228 KB Output is correct
7 Correct 4 ms 5100 KB Output is correct
8 Correct 4 ms 5100 KB Output is correct
9 Correct 52 ms 11884 KB Output is correct
10 Correct 14 ms 7032 KB Output is correct
11 Correct 36 ms 9452 KB Output is correct
12 Correct 27 ms 9708 KB Output is correct
13 Correct 45 ms 10988 KB Output is correct
14 Correct 29 ms 8812 KB Output is correct
15 Correct 9 ms 6016 KB Output is correct
16 Correct 37 ms 8940 KB Output is correct
17 Correct 73 ms 14572 KB Output is correct
18 Correct 39 ms 10476 KB Output is correct
19 Correct 4 ms 5100 KB Output is correct
20 Correct 4 ms 5116 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 5228 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 5100 KB Output is correct
31 Correct 4 ms 5100 KB Output is correct
32 Correct 4 ms 5100 KB Output is correct
33 Correct 4 ms 5100 KB Output is correct
34 Correct 17 ms 7660 KB Output is correct
35 Correct 40 ms 13420 KB Output is correct
36 Correct 52 ms 14336 KB Output is correct
37 Correct 99 ms 13420 KB Output is correct
38 Correct 107 ms 14060 KB Output is correct
39 Correct 38 ms 13292 KB Output is correct
40 Correct 4 ms 5100 KB Output is correct
41 Correct 28 ms 9196 KB Output is correct
42 Correct 50 ms 13676 KB Output is correct
43 Correct 10 ms 5996 KB Output is correct
44 Correct 30 ms 10476 KB Output is correct
45 Correct 39 ms 12044 KB Output is correct
46 Correct 48 ms 13804 KB Output is correct
47 Correct 18 ms 8428 KB Output is correct
48 Correct 5 ms 5356 KB Output is correct
49 Correct 201 ms 14060 KB Output is correct
50 Correct 98 ms 15468 KB Output is correct
51 Correct 153 ms 14188 KB Output is correct
52 Correct 92 ms 14956 KB Output is correct
53 Correct 85 ms 15724 KB Output is correct
54 Correct 235 ms 15308 KB Output is correct
55 Correct 73 ms 14444 KB Output is correct
56 Correct 114 ms 14700 KB Output is correct
57 Correct 84 ms 14188 KB Output is correct
58 Correct 887 ms 14956 KB Output is correct
59 Correct 891 ms 15540 KB Output is correct
60 Correct 781 ms 14828 KB Output is correct
61 Correct 930 ms 15596 KB Output is correct
62 Correct 836 ms 14860 KB Output is correct
63 Correct 966 ms 15856 KB Output is correct
64 Correct 793 ms 14444 KB Output is correct
65 Correct 4 ms 5100 KB Output is correct
66 Correct 4 ms 5100 KB Output is correct
67 Correct 830 ms 14956 KB Output is correct
68 Correct 784 ms 14828 KB Output is correct
69 Correct 608 ms 13548 KB Output is correct
70 Correct 621 ms 14444 KB Output is correct
71 Correct 687 ms 14436 KB Output is correct
72 Correct 625 ms 14188 KB Output is correct
73 Correct 664 ms 13984 KB Output is correct
74 Correct 900 ms 14828 KB Output is correct
75 Correct 707 ms 14316 KB Output is correct
76 Correct 774 ms 14912 KB Output is correct
77 Correct 157 ms 15468 KB Output is correct
78 Incorrect 78 ms 14316 KB Output isn't correct
79 Halted 0 ms 0 KB -