Submission #617248

# Submission time Handle Problem Language Result Execution time Memory
617248 2022-08-01T10:00:22 Z AmirElarbi Monochrome Points (JOI20_monochrome) C++14
100 / 100
40 ms 4960 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 dp[nax];
int n;
vi blck, wht;
ll test(int md){
    if(dp[md] != -1) return dp[md];
    ll res = 0;
    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);
        int bt = b-a-1;
        res += min(bt, 2*n-bt-2);
    }
    res /= 2;
    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 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 1 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 1 ms 1876 KB Output is correct
15 Correct 1 ms 1876 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 1 ms 1876 KB Output is correct
18 Correct 1 ms 1876 KB Output is correct
19 Correct 1 ms 1876 KB Output is correct
20 Correct 1 ms 1876 KB Output is correct
21 Correct 1 ms 1876 KB Output is correct
22 Correct 1 ms 1876 KB Output is correct
23 Correct 1 ms 1876 KB Output is correct
24 Correct 1 ms 1876 KB Output is correct
25 Correct 1 ms 1876 KB Output is correct
26 Correct 1 ms 1876 KB Output is correct
27 Correct 2 ms 1876 KB Output is correct
28 Correct 1 ms 1876 KB Output is correct
29 Correct 1 ms 1876 KB Output is correct
30 Correct 1 ms 1876 KB Output is correct
31 Correct 1 ms 1876 KB Output is correct
32 Correct 1 ms 1876 KB Output is correct
33 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 1 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 1 ms 1876 KB Output is correct
15 Correct 1 ms 1876 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 1 ms 1876 KB Output is correct
18 Correct 1 ms 1876 KB Output is correct
19 Correct 1 ms 1876 KB Output is correct
20 Correct 1 ms 1876 KB Output is correct
21 Correct 1 ms 1876 KB Output is correct
22 Correct 1 ms 1876 KB Output is correct
23 Correct 1 ms 1876 KB Output is correct
24 Correct 1 ms 1876 KB Output is correct
25 Correct 1 ms 1876 KB Output is correct
26 Correct 1 ms 1876 KB Output is correct
27 Correct 2 ms 1876 KB Output is correct
28 Correct 1 ms 1876 KB Output is correct
29 Correct 1 ms 1876 KB Output is correct
30 Correct 1 ms 1876 KB Output is correct
31 Correct 1 ms 1876 KB Output is correct
32 Correct 1 ms 1876 KB Output is correct
33 Correct 1 ms 1876 KB Output is correct
34 Correct 1 ms 1876 KB Output is correct
35 Correct 1 ms 1876 KB Output is correct
36 Correct 2 ms 1876 KB Output is correct
37 Correct 1 ms 1876 KB Output is correct
38 Correct 1 ms 1876 KB Output is correct
39 Correct 1 ms 1876 KB Output is correct
40 Correct 1 ms 1876 KB Output is correct
41 Correct 1 ms 1876 KB Output is correct
42 Correct 1 ms 1876 KB Output is correct
43 Correct 2 ms 1876 KB Output is correct
44 Correct 1 ms 1876 KB Output is correct
45 Correct 1 ms 1876 KB Output is correct
46 Correct 1 ms 1876 KB Output is correct
47 Correct 1 ms 1876 KB Output is correct
48 Correct 1 ms 1876 KB Output is correct
49 Correct 1 ms 1876 KB Output is correct
50 Correct 1 ms 1876 KB Output is correct
51 Correct 1 ms 1876 KB Output is correct
52 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 1 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 1 ms 1876 KB Output is correct
15 Correct 1 ms 1876 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 1 ms 1876 KB Output is correct
18 Correct 1 ms 1876 KB Output is correct
19 Correct 1 ms 1876 KB Output is correct
20 Correct 1 ms 1876 KB Output is correct
21 Correct 1 ms 1876 KB Output is correct
22 Correct 1 ms 1876 KB Output is correct
23 Correct 1 ms 1876 KB Output is correct
24 Correct 1 ms 1876 KB Output is correct
25 Correct 1 ms 1876 KB Output is correct
26 Correct 1 ms 1876 KB Output is correct
27 Correct 2 ms 1876 KB Output is correct
28 Correct 1 ms 1876 KB Output is correct
29 Correct 1 ms 1876 KB Output is correct
30 Correct 1 ms 1876 KB Output is correct
31 Correct 1 ms 1876 KB Output is correct
32 Correct 1 ms 1876 KB Output is correct
33 Correct 1 ms 1876 KB Output is correct
34 Correct 1 ms 1876 KB Output is correct
35 Correct 1 ms 1876 KB Output is correct
36 Correct 2 ms 1876 KB Output is correct
37 Correct 1 ms 1876 KB Output is correct
38 Correct 1 ms 1876 KB Output is correct
39 Correct 1 ms 1876 KB Output is correct
40 Correct 1 ms 1876 KB Output is correct
41 Correct 1 ms 1876 KB Output is correct
42 Correct 1 ms 1876 KB Output is correct
43 Correct 2 ms 1876 KB Output is correct
44 Correct 1 ms 1876 KB Output is correct
45 Correct 1 ms 1876 KB Output is correct
46 Correct 1 ms 1876 KB Output is correct
47 Correct 1 ms 1876 KB Output is correct
48 Correct 1 ms 1876 KB Output is correct
49 Correct 1 ms 1876 KB Output is correct
50 Correct 1 ms 1876 KB Output is correct
51 Correct 1 ms 1876 KB Output is correct
52 Correct 1 ms 1876 KB Output is correct
53 Correct 36 ms 4196 KB Output is correct
54 Correct 39 ms 4364 KB Output is correct
55 Correct 35 ms 4556 KB Output is correct
56 Correct 36 ms 4448 KB Output is correct
57 Correct 37 ms 4444 KB Output is correct
58 Correct 37 ms 4452 KB Output is correct
59 Correct 34 ms 4224 KB Output is correct
60 Correct 37 ms 4580 KB Output is correct
61 Correct 35 ms 4572 KB Output is correct
62 Correct 34 ms 4580 KB Output is correct
63 Correct 40 ms 4580 KB Output is correct
64 Correct 34 ms 4832 KB Output is correct
65 Correct 34 ms 4452 KB Output is correct
66 Correct 37 ms 4836 KB Output is correct
67 Correct 34 ms 4832 KB Output is correct
68 Correct 32 ms 4760 KB Output is correct
69 Correct 35 ms 4700 KB Output is correct
70 Correct 33 ms 4344 KB Output is correct
71 Correct 38 ms 4960 KB Output is correct
72 Correct 37 ms 4960 KB Output is correct
73 Correct 38 ms 4556 KB Output is correct