Submission #614023

#TimeUsernameProblemLanguageResultExecution timeMemory
614023MohamedAliSaidaneMonochrome Points (JOI20_monochrome)C++14
35 / 100
2066 ms7120 KiB
#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 compute(int x)
    {
        if(x >= n)
            return 0 ;
        if(dp[x] != -1)
            return dp[x];
        vpi inter;
        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)});
        }
        int rep = 0;
        for(int i  =  0 ; i < n - 1;i ++)
        {
            for(int j=  i + 1; j < n; j ++)
            {
                int a = inter[i].ff;
                int b = inter[i].ss;
                int c = inter[j].ff;
                int d=  inter[j].ss;
                if(c < a && b < d)
                    continue;
                if(a < c && d < b)
                    continue;
                if(d < a)
                    continue;
                if(b < c)
                    continue;
                rep ++;
            }
        }
        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;
        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 (stderr)

monochrome.cpp: In function 'int32_t main()':
monochrome.cpp:81:13: warning: variable 'rep' set but not used [-Wunused-but-set-variable]
   81 |         int rep = debut;
      |             ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...