Submission #614033

# Submission time Handle Problem Language Result Execution time Memory
614033 2022-07-30T17:16:43 Z MohamedAliSaidane Monochrome Points (JOI20_monochrome) C++14
35 / 100
2000 ms 12800 KB
#include<bits/stdc++.h>

    using namespace std;

    typedef long long ll;

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

    typedef vector<int> vi;
    typedef vector<ll> vll;
    typedef vector<pii> vpi;
    typedef vector<pll> vpl;

    #define pb push_back
    #define popb pop_back
    #define all(x) (x).begin(), (x).end()


    #define ff first
    #define ss second

    const int nax = 4e5 + 4;
    int n;
    int col[nax], dp[nax];
    vi perm, ot;
    int k  = 1;
    vi st;
    void update(int i, int delt)
    {
        i += k;
        st[i] += delt;
        i /= 2;
        while(i)
        {
            st[i] = st[2 * i ] + st[2 * i + 1];
            i /= 2;
        }
    }
    int query(int p ,int l, int r, int i, int j)
    {
        if( i  > j )
            return 0;
        if(l >= i && r <= j)
            return st[p];
        int m = (l + r)/2;
        if(m + 1 > j)
            return query(2 * p, l, m ,i ,min(j, m));
        else if(i > m)
            return query(2 * p + 1, m + 1, r, max(i,m + 1), j);
        else
        return query(2 * p, l, m ,i ,min(j, m))
             + query(2 * p + 1, m + 1, r, max(i,m + 1), j);

    }

    int compute(int x)
    {
        if(x >= n)
            return 0 ;
        if(dp[x] != -1)
            return dp[x];
        vpi inter;
        int rep = 0;
        for(int i=  0 ; i < n; i++)
        {
            int a = perm[(i + x)%n];
            int b = ot[i];
            inter.pb({min(a,b), max(a,b)});
        }
        sort(all(inter));
        reverse(all(inter));
        for(int i=  0 ; i < n; i++)
        {
            int a = inter[i].ff;
            int b=  inter[i].ss;
            rep += query(1, 0, k - 1, a, b);
            update(a, 1);
            update(b, -1);
        }
        for(int i = 0 ;  i < n; i++)
        {
            int a = inter[i].ff;
            int b  = inter[i].ss;
            update(a, -1);
            update(b, 1);
        }
        //cout << x << " " << rep <<"\n";
        return dp[x] = rep;

    }
    int32_t main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
        memset(dp, -1,sizeof(dp));
        cin >> n;
        k = 1;
        while(k < 2  * n)
            k = (k << 1);
        st.assign(2 * k + 1, 0 );
        for(int i  = 0 ; i < 2 * n ; i++)
        {
            char c; cin >> c;
            if(c == 'B')
                col[i] = 1;
            if(col[i])
                perm.pb(i);
            else
                ot.pb(i);
        }
        int ans = 0 ;
        int debut = 0;
        int fin = n - 1;
        int rep = debut;
        while(debut <= fin )
        {
            int mid = (debut + fin)/2;
            //cout << mid << ' ' << compute(mid) << ' ' << compute(mid + 1) << "\n";
            if(compute(mid + 1) > compute(mid))
            {
                rep = mid + 1;
                debut = mid + 1;
                ans = max(ans, compute(mid + 1));
            }
            else
            {
                rep = mid ;
                fin = mid - 1;
                ans = max(ans, compute(mid ));
            }
        }
        cout << ans;
    }

Compilation message

monochrome.cpp: In function 'int32_t main()':
monochrome.cpp:115:13: warning: variable 'rep' set but not used [-Wunused-but-set-variable]
  115 |         int rep = debut;
      |             ^~~
# 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 2 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1876 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 1 ms 1876 KB Output is correct
10 Correct 1 ms 1876 KB Output is correct
11 Correct 1 ms 1876 KB Output is correct
12 Correct 1 ms 1876 KB Output is correct
13 Correct 1 ms 1876 KB Output is correct
# 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 2 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1876 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 1 ms 1876 KB Output is correct
10 Correct 1 ms 1876 KB Output is correct
11 Correct 1 ms 1876 KB Output is correct
12 Correct 1 ms 1876 KB Output is correct
13 Correct 1 ms 1876 KB Output is correct
14 Correct 2 ms 1876 KB Output is correct
15 Correct 2 ms 1876 KB Output is correct
16 Correct 2 ms 1876 KB Output is correct
17 Correct 2 ms 1876 KB Output is correct
18 Correct 3 ms 1876 KB Output is correct
19 Correct 2 ms 1876 KB Output is correct
20 Correct 2 ms 1876 KB Output is correct
21 Correct 2 ms 1876 KB Output is correct
22 Correct 2 ms 1876 KB Output is correct
23 Correct 2 ms 1876 KB Output is correct
24 Correct 3 ms 1876 KB Output is correct
25 Correct 2 ms 1876 KB Output is correct
26 Correct 2 ms 1876 KB Output is correct
27 Correct 2 ms 1876 KB Output is correct
28 Correct 2 ms 1876 KB Output is correct
29 Correct 2 ms 1876 KB Output is correct
30 Correct 2 ms 1876 KB Output is correct
31 Correct 3 ms 1876 KB Output is correct
32 Correct 3 ms 1876 KB Output is correct
33 Correct 2 ms 1876 KB Output is correct
# 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 2 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1876 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 1 ms 1876 KB Output is correct
10 Correct 1 ms 1876 KB Output is correct
11 Correct 1 ms 1876 KB Output is correct
12 Correct 1 ms 1876 KB Output is correct
13 Correct 1 ms 1876 KB Output is correct
14 Correct 2 ms 1876 KB Output is correct
15 Correct 2 ms 1876 KB Output is correct
16 Correct 2 ms 1876 KB Output is correct
17 Correct 2 ms 1876 KB Output is correct
18 Correct 3 ms 1876 KB Output is correct
19 Correct 2 ms 1876 KB Output is correct
20 Correct 2 ms 1876 KB Output is correct
21 Correct 2 ms 1876 KB Output is correct
22 Correct 2 ms 1876 KB Output is correct
23 Correct 2 ms 1876 KB Output is correct
24 Correct 3 ms 1876 KB Output is correct
25 Correct 2 ms 1876 KB Output is correct
26 Correct 2 ms 1876 KB Output is correct
27 Correct 2 ms 1876 KB Output is correct
28 Correct 2 ms 1876 KB Output is correct
29 Correct 2 ms 1876 KB Output is correct
30 Correct 2 ms 1876 KB Output is correct
31 Correct 3 ms 1876 KB Output is correct
32 Correct 3 ms 1876 KB Output is correct
33 Correct 2 ms 1876 KB Output is correct
34 Correct 12 ms 1988 KB Output is correct
35 Correct 12 ms 1992 KB Output is correct
36 Correct 13 ms 1876 KB Output is correct
37 Correct 12 ms 1876 KB Output is correct
38 Correct 11 ms 1876 KB Output is correct
39 Correct 14 ms 1992 KB Output is correct
40 Correct 11 ms 1992 KB Output is correct
41 Correct 11 ms 1876 KB Output is correct
42 Correct 12 ms 1876 KB Output is correct
43 Correct 12 ms 1876 KB Output is correct
44 Correct 12 ms 1988 KB Output is correct
45 Correct 12 ms 1876 KB Output is correct
46 Correct 11 ms 1876 KB Output is correct
47 Correct 12 ms 1988 KB Output is correct
48 Correct 11 ms 1876 KB Output is correct
49 Correct 12 ms 1992 KB Output is correct
50 Correct 12 ms 1876 KB Output is correct
51 Correct 13 ms 2004 KB Output is correct
52 Correct 13 ms 1992 KB Output is correct
# 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 2 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1876 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 1 ms 1876 KB Output is correct
10 Correct 1 ms 1876 KB Output is correct
11 Correct 1 ms 1876 KB Output is correct
12 Correct 1 ms 1876 KB Output is correct
13 Correct 1 ms 1876 KB Output is correct
14 Correct 2 ms 1876 KB Output is correct
15 Correct 2 ms 1876 KB Output is correct
16 Correct 2 ms 1876 KB Output is correct
17 Correct 2 ms 1876 KB Output is correct
18 Correct 3 ms 1876 KB Output is correct
19 Correct 2 ms 1876 KB Output is correct
20 Correct 2 ms 1876 KB Output is correct
21 Correct 2 ms 1876 KB Output is correct
22 Correct 2 ms 1876 KB Output is correct
23 Correct 2 ms 1876 KB Output is correct
24 Correct 3 ms 1876 KB Output is correct
25 Correct 2 ms 1876 KB Output is correct
26 Correct 2 ms 1876 KB Output is correct
27 Correct 2 ms 1876 KB Output is correct
28 Correct 2 ms 1876 KB Output is correct
29 Correct 2 ms 1876 KB Output is correct
30 Correct 2 ms 1876 KB Output is correct
31 Correct 3 ms 1876 KB Output is correct
32 Correct 3 ms 1876 KB Output is correct
33 Correct 2 ms 1876 KB Output is correct
34 Correct 12 ms 1988 KB Output is correct
35 Correct 12 ms 1992 KB Output is correct
36 Correct 13 ms 1876 KB Output is correct
37 Correct 12 ms 1876 KB Output is correct
38 Correct 11 ms 1876 KB Output is correct
39 Correct 14 ms 1992 KB Output is correct
40 Correct 11 ms 1992 KB Output is correct
41 Correct 11 ms 1876 KB Output is correct
42 Correct 12 ms 1876 KB Output is correct
43 Correct 12 ms 1876 KB Output is correct
44 Correct 12 ms 1988 KB Output is correct
45 Correct 12 ms 1876 KB Output is correct
46 Correct 11 ms 1876 KB Output is correct
47 Correct 12 ms 1988 KB Output is correct
48 Correct 11 ms 1876 KB Output is correct
49 Correct 12 ms 1992 KB Output is correct
50 Correct 12 ms 1876 KB Output is correct
51 Correct 13 ms 2004 KB Output is correct
52 Correct 13 ms 1992 KB Output is correct
53 Execution timed out 2080 ms 12800 KB Time limit exceeded
54 Halted 0 ms 0 KB -