Submission #925882

# Submission time Handle Problem Language Result Execution time Memory
925882 2024-02-12T10:22:34 Z boris_mihov Monochrome Points (JOI20_monochrome) C++17
25 / 100
2000 ms 2652 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];
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] == 'W') w[cntW++] = i;
        else b[cntB++] = i;
    }

    int max = 0;
    for (int i = 0 ; i < n ; ++i)
    {
        max = std::max(max, solveFor(i));
    }

    std::cout << max << '\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:64:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   64 |     std::cin >> s + 1;
      |                 ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2512 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2480 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2512 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2480 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 14 ms 2392 KB Output is correct
15 Correct 15 ms 2396 KB Output is correct
16 Correct 18 ms 2652 KB Output is correct
17 Correct 13 ms 2396 KB Output is correct
18 Correct 10 ms 2520 KB Output is correct
19 Correct 12 ms 2396 KB Output is correct
20 Correct 11 ms 2528 KB Output is correct
21 Correct 16 ms 2396 KB Output is correct
22 Correct 12 ms 2520 KB Output is correct
23 Correct 5 ms 2516 KB Output is correct
24 Correct 10 ms 2532 KB Output is correct
25 Correct 10 ms 2396 KB Output is correct
26 Correct 10 ms 2396 KB Output is correct
27 Correct 10 ms 2392 KB Output is correct
28 Correct 12 ms 2396 KB Output is correct
29 Correct 9 ms 2396 KB Output is correct
30 Correct 11 ms 2392 KB Output is correct
31 Correct 17 ms 2648 KB Output is correct
32 Correct 13 ms 2396 KB Output is correct
33 Correct 16 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2512 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2480 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 14 ms 2392 KB Output is correct
15 Correct 15 ms 2396 KB Output is correct
16 Correct 18 ms 2652 KB Output is correct
17 Correct 13 ms 2396 KB Output is correct
18 Correct 10 ms 2520 KB Output is correct
19 Correct 12 ms 2396 KB Output is correct
20 Correct 11 ms 2528 KB Output is correct
21 Correct 16 ms 2396 KB Output is correct
22 Correct 12 ms 2520 KB Output is correct
23 Correct 5 ms 2516 KB Output is correct
24 Correct 10 ms 2532 KB Output is correct
25 Correct 10 ms 2396 KB Output is correct
26 Correct 10 ms 2396 KB Output is correct
27 Correct 10 ms 2392 KB Output is correct
28 Correct 12 ms 2396 KB Output is correct
29 Correct 9 ms 2396 KB Output is correct
30 Correct 11 ms 2392 KB Output is correct
31 Correct 17 ms 2648 KB Output is correct
32 Correct 13 ms 2396 KB Output is correct
33 Correct 16 ms 2396 KB Output is correct
34 Execution timed out 2071 ms 2392 KB Time limit exceeded
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2512 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2480 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 14 ms 2392 KB Output is correct
15 Correct 15 ms 2396 KB Output is correct
16 Correct 18 ms 2652 KB Output is correct
17 Correct 13 ms 2396 KB Output is correct
18 Correct 10 ms 2520 KB Output is correct
19 Correct 12 ms 2396 KB Output is correct
20 Correct 11 ms 2528 KB Output is correct
21 Correct 16 ms 2396 KB Output is correct
22 Correct 12 ms 2520 KB Output is correct
23 Correct 5 ms 2516 KB Output is correct
24 Correct 10 ms 2532 KB Output is correct
25 Correct 10 ms 2396 KB Output is correct
26 Correct 10 ms 2396 KB Output is correct
27 Correct 10 ms 2392 KB Output is correct
28 Correct 12 ms 2396 KB Output is correct
29 Correct 9 ms 2396 KB Output is correct
30 Correct 11 ms 2392 KB Output is correct
31 Correct 17 ms 2648 KB Output is correct
32 Correct 13 ms 2396 KB Output is correct
33 Correct 16 ms 2396 KB Output is correct
34 Execution timed out 2071 ms 2392 KB Time limit exceeded
35 Halted 0 ms 0 KB -