Submission #440549

# Submission time Handle Problem Language Result Execution time Memory
440549 2021-07-02T12:36:47 Z leaked Chessboard (IZhO18_chessboard) C++14
100 / 100
1816 ms 9284 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker,"/stack:20000000")
//#pragma GCC target("sse,sse2,sse3,sse3,ssse3,abm,avx,avx2,tune=native")
#define f first
#define s second
#define endl '\n'
#define vec vector
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define m_p make_pair
#define sz(x) (int)x.size()
#define pw(x) (1LL<<x)

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

auto rng=bind(uniform_int_distribution<int>(0,1e9),mt19937(time(0)));

template<class T>bool umin(T &a,const T &b) {return (a>b?a=b,1:0);}
template<class T>bool umax(T &a,const T &b) {return (a<b?a=b,1:0);}
template<class T> using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//vec<int>tos={}
const int N=1e5+1;
int nxt(int x,int k){
    x+=(k-x%k);
    return x;
}
int prv(int x,int k){
    x-=(x%k);x--;
    return x;
}
int get(int x,int k){
    return (x/k)&1;
}
pii get(int l,int r,int k){
    int dl=r-l+1;
    while(get(l,k)!=0) l=nxt(l,k);
    while(get(r,k)!=0) r=prv(r,k);
    int x=0;
    if(l>r) x=0;
    else if(l<=r){
        if((l/k)==(r/k)){
            x=r-l+1;
        }
        else{
            x+=nxt(l,k)-l;
            x+=r-prv(r,k);
            l=nxt(l,k);r=prv(r,k);
            assert(l%k==0);assert(r%k==k-1);
            int how=(r-l+1)/k;
            how/=2;
            x+=how*k;
        }
    }
    return {x,dl-x};
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,q;
    cin>>n>>q;
    ll ans=1ll*n*n;
    vec<vec<array<int,3>>>scan(n+1,vec<array<int,3>>());
    for(int i=0;i<q;i++){
        int x1,x2,y1,y2;
        cin>>x1>>y1>>x2>>y2;
        --x1;--x2;--y1;--y2;
        scan[y1].pb({x1,x2,1});
        scan[y2+1].pb({x1,x2,-1});
    }
    vec<int>ch(n,0);
    for(int x=1;x<n;x++){
        if(n%x) continue;
        //cerr<<"HERE "<<endl;
        vec<int>cnt(2,0);
        vec<int>cr(2,0);
        for(int j=0;j<n;j++){
            ch[j]=((j/x)&1);
            cnt[ch[j]]++;
        }
        vec<ll>answ(2,0);
        int k=x;
        for(int i=0;i<=n;i++){
            for(auto &z : scan[i]){
                int l=z[0],r=z[1];
                cr[0]+=get(l,r,k).f*z[2];
                cr[1]+=get(l,r,k).s*z[2];
            }
            if(i==n) continue;
//            if(i && ch[i]!=ch[i-1]) swap(cr[0],cr[1]);
            int a=cr[0],b=cr[1];
            if(ch[i]){
                int x=a+cnt[1]-b;
                answ[1]+=x;
                x=n-x;
                answ[0]+=x;
            }
            else{
                int x=a+cnt[1]-b;
                answ[0]+=x;
                x=n-x;
                answ[1]+=x;
            }
        }
        umin(ans,answ[0]);
        umin(ans,answ[1]);
    }
    cout<<ans;
    return 0;
}
/*

*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 4540 KB Output is correct
2 Correct 12 ms 1612 KB Output is correct
3 Correct 31 ms 5328 KB Output is correct
4 Correct 28 ms 3148 KB Output is correct
5 Correct 42 ms 5332 KB Output is correct
6 Correct 27 ms 3840 KB Output is correct
7 Correct 7 ms 1476 KB Output is correct
8 Correct 29 ms 3920 KB Output is correct
9 Correct 70 ms 6784 KB Output is correct
10 Correct 40 ms 4596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 328 KB Output is correct
16 Correct 20 ms 1788 KB Output is correct
17 Correct 44 ms 5028 KB Output is correct
18 Correct 69 ms 5188 KB Output is correct
19 Correct 270 ms 4976 KB Output is correct
20 Correct 304 ms 5188 KB Output is correct
21 Correct 41 ms 4952 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 50 ms 2584 KB Output is correct
24 Correct 66 ms 5040 KB Output is correct
25 Correct 10 ms 852 KB Output is correct
26 Correct 40 ms 3112 KB Output is correct
27 Correct 63 ms 4496 KB Output is correct
28 Correct 68 ms 5060 KB Output is correct
29 Correct 22 ms 2308 KB Output is correct
30 Correct 3 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 4540 KB Output is correct
2 Correct 12 ms 1612 KB Output is correct
3 Correct 31 ms 5328 KB Output is correct
4 Correct 28 ms 3148 KB Output is correct
5 Correct 42 ms 5332 KB Output is correct
6 Correct 27 ms 3840 KB Output is correct
7 Correct 7 ms 1476 KB Output is correct
8 Correct 29 ms 3920 KB Output is correct
9 Correct 70 ms 6784 KB Output is correct
10 Correct 40 ms 4596 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 324 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 2 ms 328 KB Output is correct
26 Correct 20 ms 1788 KB Output is correct
27 Correct 44 ms 5028 KB Output is correct
28 Correct 69 ms 5188 KB Output is correct
29 Correct 270 ms 4976 KB Output is correct
30 Correct 304 ms 5188 KB Output is correct
31 Correct 41 ms 4952 KB Output is correct
32 Correct 2 ms 332 KB Output is correct
33 Correct 50 ms 2584 KB Output is correct
34 Correct 66 ms 5040 KB Output is correct
35 Correct 10 ms 852 KB Output is correct
36 Correct 40 ms 3112 KB Output is correct
37 Correct 63 ms 4496 KB Output is correct
38 Correct 68 ms 5060 KB Output is correct
39 Correct 22 ms 2308 KB Output is correct
40 Correct 3 ms 460 KB Output is correct
41 Correct 314 ms 8512 KB Output is correct
42 Correct 99 ms 9284 KB Output is correct
43 Correct 187 ms 8488 KB Output is correct
44 Correct 102 ms 8956 KB Output is correct
45 Correct 75 ms 9284 KB Output is correct
46 Correct 343 ms 9092 KB Output is correct
47 Correct 88 ms 8516 KB Output is correct
48 Correct 159 ms 8716 KB Output is correct
49 Correct 83 ms 8476 KB Output is correct
50 Correct 1659 ms 8492 KB Output is correct
51 Correct 1776 ms 8868 KB Output is correct
52 Correct 1613 ms 8444 KB Output is correct
53 Correct 1677 ms 8716 KB Output is correct
54 Correct 1595 ms 8368 KB Output is correct
55 Correct 1791 ms 9064 KB Output is correct
56 Correct 1500 ms 8188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 44 ms 4540 KB Output is correct
10 Correct 12 ms 1612 KB Output is correct
11 Correct 31 ms 5328 KB Output is correct
12 Correct 28 ms 3148 KB Output is correct
13 Correct 42 ms 5332 KB Output is correct
14 Correct 27 ms 3840 KB Output is correct
15 Correct 7 ms 1476 KB Output is correct
16 Correct 29 ms 3920 KB Output is correct
17 Correct 70 ms 6784 KB Output is correct
18 Correct 40 ms 4596 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 324 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 2 ms 328 KB Output is correct
34 Correct 20 ms 1788 KB Output is correct
35 Correct 44 ms 5028 KB Output is correct
36 Correct 69 ms 5188 KB Output is correct
37 Correct 270 ms 4976 KB Output is correct
38 Correct 304 ms 5188 KB Output is correct
39 Correct 41 ms 4952 KB Output is correct
40 Correct 2 ms 332 KB Output is correct
41 Correct 50 ms 2584 KB Output is correct
42 Correct 66 ms 5040 KB Output is correct
43 Correct 10 ms 852 KB Output is correct
44 Correct 40 ms 3112 KB Output is correct
45 Correct 63 ms 4496 KB Output is correct
46 Correct 68 ms 5060 KB Output is correct
47 Correct 22 ms 2308 KB Output is correct
48 Correct 3 ms 460 KB Output is correct
49 Correct 314 ms 8512 KB Output is correct
50 Correct 99 ms 9284 KB Output is correct
51 Correct 187 ms 8488 KB Output is correct
52 Correct 102 ms 8956 KB Output is correct
53 Correct 75 ms 9284 KB Output is correct
54 Correct 343 ms 9092 KB Output is correct
55 Correct 88 ms 8516 KB Output is correct
56 Correct 159 ms 8716 KB Output is correct
57 Correct 83 ms 8476 KB Output is correct
58 Correct 1659 ms 8492 KB Output is correct
59 Correct 1776 ms 8868 KB Output is correct
60 Correct 1613 ms 8444 KB Output is correct
61 Correct 1677 ms 8716 KB Output is correct
62 Correct 1595 ms 8368 KB Output is correct
63 Correct 1791 ms 9064 KB Output is correct
64 Correct 1500 ms 8188 KB Output is correct
65 Correct 0 ms 204 KB Output is correct
66 Correct 0 ms 204 KB Output is correct
67 Correct 1661 ms 8372 KB Output is correct
68 Correct 1680 ms 8344 KB Output is correct
69 Correct 1446 ms 7536 KB Output is correct
70 Correct 1580 ms 8044 KB Output is correct
71 Correct 1602 ms 8048 KB Output is correct
72 Correct 1558 ms 7940 KB Output is correct
73 Correct 1495 ms 7804 KB Output is correct
74 Correct 1665 ms 8324 KB Output is correct
75 Correct 1623 ms 8020 KB Output is correct
76 Correct 1698 ms 8352 KB Output is correct
77 Correct 276 ms 8984 KB Output is correct
78 Correct 96 ms 8448 KB Output is correct
79 Correct 196 ms 8304 KB Output is correct
80 Correct 203 ms 8504 KB Output is correct
81 Correct 186 ms 8132 KB Output is correct
82 Correct 164 ms 8916 KB Output is correct
83 Correct 129 ms 8524 KB Output is correct
84 Correct 1026 ms 9024 KB Output is correct
85 Correct 1694 ms 8708 KB Output is correct
86 Correct 155 ms 2508 KB Output is correct
87 Correct 135 ms 2508 KB Output is correct
88 Correct 1816 ms 8732 KB Output is correct
89 Correct 463 ms 3940 KB Output is correct
90 Correct 136 ms 2588 KB Output is correct