Submission #925908

# Submission time Handle Problem Language Result Execution time Memory
925908 2024-02-12T10:35:26 Z boris_mihov Monochrome Points (JOI20_monochrome) C++17
35 / 100
2000 ms 7128 KB
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <set>

typedef long long llong;
const int MAXN = 400000 + 10;
const int INF  = 2e9;

int n;
int w[MAXN];
int b[MAXN];
char s[MAXN];
int f[MAXN];
int fPrim[MAXN];
std::vector <std::pair <int,int>> v;

int solveFor(int k)
{
    v.clear();
    for (int i = 1 ; i <= n ; ++i)
    {
        v.push_back({std::min(w[i], b[(i + k - 1) % n + 1]), std::max(w[i], b[(i + k - 1) % n + 1])});
    }

    int res = 0;
    std::sort(v.begin(), v.end());
    for (int i = 0 ; i < n ; ++i)
    {
        for (int j = i + 1 ; j < n ; ++j)
        {
            res += (v[j].first < v[i].second && v[i].second < v[j].second);
        }
    }

    return res;
}

void solve()
{
    int cntW = 1;
    int cntB = 1;
    for (int i = 1 ; i <= 2 * n ; ++i)
    {
        if (s[i] == s[1]) w[cntW++] = i;
        else b[cntB++] = i;
    }

    int l = 0, r = n - 1, mid;
    while (l < r - 1)
    {
        mid = (l + r) / 2;
        if (solveFor(mid) - solveFor(mid - 1) >= 0) l = mid;
        else r = mid;
    }

    int res = std::max(solveFor(0), solveFor(n - 1));
    std::cout << std::max(res, solveFor(l)) << '\n';
}

void input()
{
    std::cin >> n;
    std::cin >> s + 1;
}

void fastIOI()
{
    std::ios_base :: sync_with_stdio(0);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);
}   

int main()
{
    fastIOI();
    input();
    solve();

    return 0;
}

Compilation message

monochrome.cpp: In function 'void input()':
monochrome.cpp:69:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   69 |     std::cin >> s + 1;
      |                 ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4696 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4696 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 2 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 2 ms 4568 KB Output is correct
18 Correct 1 ms 4696 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 2 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 2 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 2 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4696 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 2 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4696 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 2 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 2 ms 4568 KB Output is correct
18 Correct 1 ms 4696 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 2 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 2 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 2 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4696 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 2 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 37 ms 4444 KB Output is correct
35 Correct 37 ms 4444 KB Output is correct
36 Correct 41 ms 4444 KB Output is correct
37 Correct 35 ms 4444 KB Output is correct
38 Correct 42 ms 4444 KB Output is correct
39 Correct 36 ms 4444 KB Output is correct
40 Correct 36 ms 4444 KB Output is correct
41 Correct 29 ms 4444 KB Output is correct
42 Correct 37 ms 4440 KB Output is correct
43 Correct 37 ms 4440 KB Output is correct
44 Correct 31 ms 4440 KB Output is correct
45 Correct 39 ms 4444 KB Output is correct
46 Correct 35 ms 4440 KB Output is correct
47 Correct 38 ms 4440 KB Output is correct
48 Correct 37 ms 4444 KB Output is correct
49 Correct 31 ms 4444 KB Output is correct
50 Correct 32 ms 4440 KB Output is correct
51 Correct 32 ms 4444 KB Output is correct
52 Correct 37 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4696 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 2 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 2 ms 4568 KB Output is correct
18 Correct 1 ms 4696 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 2 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 2 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 2 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4696 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 2 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 37 ms 4444 KB Output is correct
35 Correct 37 ms 4444 KB Output is correct
36 Correct 41 ms 4444 KB Output is correct
37 Correct 35 ms 4444 KB Output is correct
38 Correct 42 ms 4444 KB Output is correct
39 Correct 36 ms 4444 KB Output is correct
40 Correct 36 ms 4444 KB Output is correct
41 Correct 29 ms 4444 KB Output is correct
42 Correct 37 ms 4440 KB Output is correct
43 Correct 37 ms 4440 KB Output is correct
44 Correct 31 ms 4440 KB Output is correct
45 Correct 39 ms 4444 KB Output is correct
46 Correct 35 ms 4440 KB Output is correct
47 Correct 38 ms 4440 KB Output is correct
48 Correct 37 ms 4444 KB Output is correct
49 Correct 31 ms 4444 KB Output is correct
50 Correct 32 ms 4440 KB Output is correct
51 Correct 32 ms 4444 KB Output is correct
52 Correct 37 ms 4440 KB Output is correct
53 Execution timed out 2054 ms 7128 KB Time limit exceeded
54 Halted 0 ms 0 KB -