Submission #617218

# Submission time Handle Problem Language Result Execution time Memory
617218 2022-08-01T09:44:47 Z AmirElarbi Monochrome Points (JOI20_monochrome) C++14
0 / 100
1 ms 1876 KB
#include <bits/stdc++.h>
#define vi vector<int>
#define ve vector
#define ll long long
#define vf vector<float>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define pll pair<ll,ll>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 2e9+5
#define eps 1e-7
#define eps1 1e-25
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 1e5+5
#define V 450
using namespace std;
const int MOD = 1e9;
const int nax = 2e5+5;
const int lg = 20;
ll st[nax*8], dp[nax];
int n;
void rset(int v, int l, int r){
    if(st[v] == 0) return;
    if(l == r){
        st[v] = 0;
        return;
    }
    int md = (l+r)/2;
    rset(v*2,l, md);
    rset(v*2+1,md+1, r);
    st[v]=0;
}
void update(int v, int l, int r, int pos, int val){
    if(pos > r || pos < l) return;
    if(l == r){
        st[v] += val;
        return;
    }
    int md = (l+r)/2;
    update(v*2, l, md, pos, val);
    update(v*2+1, md+1, r, pos, val);
    st[v] = st[v*2]+st[v*2+1];
}
ll query(int v, int l, int r, int i, int j){
    if(i > r || j < l) return 0;
    if(i <= l && r <= j) return st[v];
    int md = (l+r)/2;
    return query(v*2, l, md, i, j)+ query(v*2+1, md+1, r, i, j);
}
vi blck, wht;
ll test(int md){
    if(dp[md] != -1) return dp[md];
    int res = 0;
    rset(1,0,2*n-1);
    set<ii> qr;
    for (int j = 0; j < n; ++j)
    {
        int ind = (j+md)%n;
        int a = blck[j], b = wht[ind];
        if(a > b) swap(a,b);
        qr.insert({-a,-b});
    }
    for(auto x : qr){
        res += query(1,0,2*n-1, -x.fi, -x.se);
        update(1,0,2*n-1, -x.fi, 1);
        update(1,0,2*n-1, -x.se, -1);
    }
    return dp[md] = res;
}
int main() {
    optimise;
    cin >> n;
    string s;
    cin >> s;
    memset(dp, -1, sizeof dp);
    for (int i = 0; i < n*2; ++i)
    {
        if(s[i] == 'B') blck.pb(i);
        if(s[i] == 'W') wht.pb(i);
    }
    ll mx = 0;
    int l = 0, r = n;
    while (l < r)
    {
        int md = (l+r)/2;
        ll a = test(md+1), b = test(md);
        if(a > b){
            mx = max(mx, a);
            l = md+1;
        } else {
            mx = max(mx, b);
            r = md;
        }
    }
    cout << mx << '\n';
}


# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Incorrect 1 ms 1876 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Incorrect 1 ms 1876 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Incorrect 1 ms 1876 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Incorrect 1 ms 1876 KB Output isn't correct
7 Halted 0 ms 0 KB -