Submission #495374

# Submission time Handle Problem Language Result Execution time Memory
495374 2021-12-18T14:24:38 Z 600Mihnea Monochrome Points (JOI20_monochrome) C++17
35 / 100
2000 ms 4564 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll solve(string s) {
  int n = (int) s.size() / 2;
  vector<int> a, b;
  for (int i = 0; i < 2 * n; i++) {
    if (s[i] != s[0]) {
      a.push_back(i);
    }
    else {
      b.push_back(i);
    }
  }
  vector<ll> cnt(n, -n);

  function<void(int, int, int)> add = [&] (int l, int r, int x) {
    if (l <= r) {
      for (int j = l; j <= r; j++) {
        cnt[j] += x;
      }
    } else {
      add(l, n - 1, x);
      add(0, r, x);
    }
  };

  int pt = 0, pt2 = 0, pt3 = 0;

  for (int i = 0; i < n; i++) {
    while (pt < n && b[pt] < a[i]) {
      pt++;
    }

    while (pt2 < n && a[i] >= n + b[pt2]) {
      pt2++;
    }

    while (pt3 < n && b[pt3] < n + a[i]) {
      pt3++;
    }

    if (pt < pt3) {
      add((n - i + pt) % n, (n - i + pt3 - 1) % n, -a[i]);
    }
    if (pt3 < n) {
      add((n - i + pt3) % n, (n - i + n - 1) % n, 2 * n + a[i]);
    }

    if (0 < pt2) {
      add((n - i) % n, (n - i + pt2 - 1) % n, 2 * n - a[i]);
    }
    if (pt2 < pt) {
      add((n - i + pt2) % n, (n - i + pt - 1) % n, a[i]);
    }

  }


  pt = 0;
  pt2 = 0;
  pt3 = 0;

  for (int j = 0; j < n; j++) {
    while (pt < n && a[pt] < b[j]) {
      pt++;
    }

    while (pt2 < n && b[j] >= n + a[pt2]) {
      pt2++;
    }

    while (pt3 < n && a[pt3] < n + b[j]) {
      pt3++;
    }

    if (0 < pt2) {
      add((n - (pt2 - 1) + j) % n, (n - 0 + j) % n, -b[j]);
    }
    if (pt2 < pt) {
      add((n - (pt - 1) + j) % n, (n - pt2 + j) % n, b[j]);
    }

    if (pt < pt3) {
      add((n - (pt3 - 1) + j) % n, (n - pt + j) % n, -b[j]);
    }

    if (pt3 < n) {
      add((n - (n - 1) + j) % n, (n - pt3 + j) % n, b[j]);
    }

  }

  ll sol = 0;
  for (auto &x : cnt) {
    sol = max(sol, x);
  }
  return sol /2;
}

int main() {
  ios::sync_with_stdio(0); cin.tie(0);


  if (0) {
    assert(solve("WWWBWBBBBWWBWWBWWBBWWBBBWBBBWWBW") == 105);
    assert(solve("WBBBWBBWWBWWBWWBWBWB") == 41);
    assert(solve("BWBWBBWBWW") == 8);
    assert(solve("BBWWBW") == 2);

    cout << "ok!\n";
    exit(0);
  }

  int n;
  string s;

  cin >> n >> s;



  cout << solve(s) << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 6 ms 332 KB Output is correct
35 Correct 5 ms 332 KB Output is correct
36 Correct 4 ms 332 KB Output is correct
37 Correct 5 ms 360 KB Output is correct
38 Correct 4 ms 332 KB Output is correct
39 Correct 4 ms 364 KB Output is correct
40 Correct 5 ms 352 KB Output is correct
41 Correct 4 ms 332 KB Output is correct
42 Correct 4 ms 332 KB Output is correct
43 Correct 6 ms 360 KB Output is correct
44 Correct 4 ms 332 KB Output is correct
45 Correct 5 ms 332 KB Output is correct
46 Correct 5 ms 332 KB Output is correct
47 Correct 5 ms 332 KB Output is correct
48 Correct 5 ms 332 KB Output is correct
49 Correct 4 ms 332 KB Output is correct
50 Correct 5 ms 332 KB Output is correct
51 Correct 5 ms 332 KB Output is correct
52 Correct 4 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 6 ms 332 KB Output is correct
35 Correct 5 ms 332 KB Output is correct
36 Correct 4 ms 332 KB Output is correct
37 Correct 5 ms 360 KB Output is correct
38 Correct 4 ms 332 KB Output is correct
39 Correct 4 ms 364 KB Output is correct
40 Correct 5 ms 352 KB Output is correct
41 Correct 4 ms 332 KB Output is correct
42 Correct 4 ms 332 KB Output is correct
43 Correct 6 ms 360 KB Output is correct
44 Correct 4 ms 332 KB Output is correct
45 Correct 5 ms 332 KB Output is correct
46 Correct 5 ms 332 KB Output is correct
47 Correct 5 ms 332 KB Output is correct
48 Correct 5 ms 332 KB Output is correct
49 Correct 4 ms 332 KB Output is correct
50 Correct 5 ms 332 KB Output is correct
51 Correct 5 ms 332 KB Output is correct
52 Correct 4 ms 332 KB Output is correct
53 Execution timed out 2082 ms 4564 KB Time limit exceeded
54 Halted 0 ms 0 KB -