Submission #379491

# Submission time Handle Problem Language Result Execution time Memory
379491 2021-03-18T10:33:49 Z qwerty234 Monochrome Points (JOI20_monochrome) C++14
100 / 100
67 ms 34156 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
#define int long long

using namespace std;

const int MAXN = 1e6 + 10;

int n, blue[MAXN], red[MAXN], l1_blue[MAXN], r1_blue[MAXN], l2_blue[MAXN], r2_blue[MAXN];
int l1_red[MAXN], r1_red[MAXN], l2_red[MAXN], r2_red[MAXN];
int closest_left_red[MAXN], closest_left_blue[MAXN];
ll ans[MAXN];
char a[MAXN];

void precalc() {
  for (int i = 1; i <= n; i++) {
    blue[i + n] = blue[i] + 2 * n;
    red[i + n] = red[i] + 2 * n;
  }
  int lastred = 0, lastblue = 0;
  for (int i = 1; i <= 4 * n; i++) {
    int cur = i; if (i > 2 * n) cur -= 2 * n;
    if (a[cur] == 'B') lastblue++; else lastred++;
    closest_left_red[i] = lastred;
    closest_left_blue[i] = lastblue;
  }
  for (int i = 1; i <= n; i++) {
    l1_blue[i] = closest_left_red[blue[i]] + 1;
    r1_blue[i] = closest_left_red[(blue[i] + blue[i + n]) / 2];
    l2_blue[i] = r1_blue[i] + 1;
    r2_blue[i] = closest_left_red[blue[i + n]];

    l1_red[i] = closest_left_blue[red[i]] + 1;
    r1_red[i] = closest_left_blue[(red[i] + red[i + n]) / 2 - 1];
    l2_red[i] = r1_red[i] + 1;
    r2_red[i] = closest_left_blue[red[i + n]];
  }
}

void add(int l, int r, int x) {
  if (l > r)
    return;
  l = (l + 2 * n) % n;
  r = (r + 2 * n) % n;
  if (l <= r) {
    ans[l] += x;
    ans[r + 1] -= x;
  } else {
    ans[l] += x;
    ans[0] += x;
    ans[r + 1] -= x;
  }
}

main() {
//  freopen("input.txt", "r", stdin);
  cin >> n; int b = 0, r = 0;
  for (int i = 1; i <= 2 * n; i++) {
    cin >> a[i];
    if (a[i] == 'B') {
      blue[++b] = i;
    } else {
      red[++r] = i;
    }
  }
  precalc();
  for (int i = 1; i <= n; i++) {
    if (l1_blue[i] <= r1_blue[i]) {
      add(l1_blue[i] - i, r1_blue[i] - i, -blue[i]);
    }
    if (l2_blue[i] <= r2_blue[i]) {
      add(l2_blue[i] - i, r2_blue[i] - i, blue[i + n]);
    }

    if (l1_red[i] <= r1_red[i]) {
      add(i - min(n, r1_red[i]), i - l1_red[i], -red[i + n]);
      add(i - r1_red[i], i - max(n + 1, l1_red[i]), -red[i]);
    }
    if (l2_red[i] <= r2_red[i]) {
      add(i - min(n, r2_red[i]), i - l2_red[i], red[i + n]);
      add(i - r2_red[i], i - max(n + 1, l2_red[i]), red[i]);
    }
  }
  ans[0] -= n;
  ll anss = 0, cur = 0;
  for (int i = 0; i < n; i++) {
    cur += ans[i];
    anss = max(anss, cur / 2);
  }
  cout << anss;
}

Compilation message

monochrome.cpp:58:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   58 | main() {
      |      ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 1 ms 492 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 1 ms 492 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 1 ms 492 KB Output is correct
34 Correct 1 ms 748 KB Output is correct
35 Correct 1 ms 748 KB Output is correct
36 Correct 1 ms 748 KB Output is correct
37 Correct 1 ms 748 KB Output is correct
38 Correct 1 ms 748 KB Output is correct
39 Correct 1 ms 748 KB Output is correct
40 Correct 1 ms 748 KB Output is correct
41 Correct 1 ms 748 KB Output is correct
42 Correct 1 ms 748 KB Output is correct
43 Correct 1 ms 748 KB Output is correct
44 Correct 1 ms 748 KB Output is correct
45 Correct 1 ms 748 KB Output is correct
46 Correct 1 ms 748 KB Output is correct
47 Correct 1 ms 748 KB Output is correct
48 Correct 1 ms 748 KB Output is correct
49 Correct 1 ms 748 KB Output is correct
50 Correct 1 ms 748 KB Output is correct
51 Correct 1 ms 876 KB Output is correct
52 Correct 1 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 1 ms 492 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 1 ms 492 KB Output is correct
34 Correct 1 ms 748 KB Output is correct
35 Correct 1 ms 748 KB Output is correct
36 Correct 1 ms 748 KB Output is correct
37 Correct 1 ms 748 KB Output is correct
38 Correct 1 ms 748 KB Output is correct
39 Correct 1 ms 748 KB Output is correct
40 Correct 1 ms 748 KB Output is correct
41 Correct 1 ms 748 KB Output is correct
42 Correct 1 ms 748 KB Output is correct
43 Correct 1 ms 748 KB Output is correct
44 Correct 1 ms 748 KB Output is correct
45 Correct 1 ms 748 KB Output is correct
46 Correct 1 ms 748 KB Output is correct
47 Correct 1 ms 748 KB Output is correct
48 Correct 1 ms 748 KB Output is correct
49 Correct 1 ms 748 KB Output is correct
50 Correct 1 ms 748 KB Output is correct
51 Correct 1 ms 876 KB Output is correct
52 Correct 1 ms 768 KB Output is correct
53 Correct 67 ms 34156 KB Output is correct
54 Correct 67 ms 34156 KB Output is correct
55 Correct 64 ms 32492 KB Output is correct
56 Correct 65 ms 32748 KB Output is correct
57 Correct 56 ms 33132 KB Output is correct
58 Correct 59 ms 34028 KB Output is correct
59 Correct 56 ms 32620 KB Output is correct
60 Correct 56 ms 32748 KB Output is correct
61 Correct 60 ms 33132 KB Output is correct
62 Correct 59 ms 33224 KB Output is correct
63 Correct 60 ms 33004 KB Output is correct
64 Correct 56 ms 32876 KB Output is correct
65 Correct 58 ms 31340 KB Output is correct
66 Correct 56 ms 32236 KB Output is correct
67 Correct 56 ms 32364 KB Output is correct
68 Correct 62 ms 30976 KB Output is correct
69 Correct 59 ms 33900 KB Output is correct
70 Correct 53 ms 31084 KB Output is correct
71 Correct 56 ms 34156 KB Output is correct
72 Correct 56 ms 34156 KB Output is correct
73 Correct 66 ms 34156 KB Output is correct