Submission #900777

# Submission time Handle Problem Language Result Execution time Memory
900777 2024-01-09T03:26:05 Z Keys Monochrome Points (JOI20_monochrome) C++14
35 / 100
2000 ms 14300 KB
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
typedef vector<int> vi;
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ROF(i, a, b) for (int i = (a); i >= (b); i--)
#define all(x) x.begin(), x.end()
#define f first
#define s second

struct ft {
    vector<int> bit; int n;
    ft(int _n) {bit.resize(_n + 5); n = _n + 5;}
    void upd(int i, int x) {i += 2; for (;i < n; i += i & (-i)) bit[i] += x;}
    int query(int i) {i += 2; int x = 0; for(; i > 0; i -= i & (-i)) x += bit[i]; return x;}
    int query(int i, int j) {if (i > j) return 0; return query(j) - query(i - 1);}
};

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n; cin >> n; string s; cin >> s;
  vi b, w; FOR(i, 0, 2 * n) {
    if (s[i] == 'B') b.pb(i);
    else w.pb(i);
  }
  auto calc = [&] (vi l, vi r) {
    ft f(2 * n + 5);
    vi ord(n); iota(all(ord), 0);
    int ans = 0;
    FOR(i, 0, n) if (r[i] < l[i]) swap(r[i], l[i]);
    sort(all(ord), [&] (int u, int v) {return l[u] < l[v];});
    FOR(j, 0, n) {
      int i = ord[j];
      ans += f.query(l[i], r[i]);
      f.upd(l[i], -1); f.upd(r[i], 1);
    }
    return ans;
  };
  vi l(n);
  for (int i = 0; i < n; i++) {
    l[i] = calc(b, w);
    rotate(b.begin(), b.begin() + 1, b.end());
  }
  cout << *max_element(all(l)) << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 456 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 456 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 5 ms 348 KB Output is correct
15 Correct 5 ms 348 KB Output is correct
16 Correct 5 ms 348 KB Output is correct
17 Correct 5 ms 348 KB Output is correct
18 Correct 3 ms 484 KB Output is correct
19 Correct 4 ms 348 KB Output is correct
20 Correct 4 ms 348 KB Output is correct
21 Correct 3 ms 484 KB Output is correct
22 Correct 4 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 3 ms 452 KB Output is correct
25 Correct 4 ms 452 KB Output is correct
26 Correct 4 ms 344 KB Output is correct
27 Correct 3 ms 348 KB Output is correct
28 Correct 5 ms 348 KB Output is correct
29 Correct 3 ms 348 KB Output is correct
30 Correct 3 ms 348 KB Output is correct
31 Correct 5 ms 348 KB Output is correct
32 Correct 4 ms 348 KB Output is correct
33 Correct 5 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 456 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 5 ms 348 KB Output is correct
15 Correct 5 ms 348 KB Output is correct
16 Correct 5 ms 348 KB Output is correct
17 Correct 5 ms 348 KB Output is correct
18 Correct 3 ms 484 KB Output is correct
19 Correct 4 ms 348 KB Output is correct
20 Correct 4 ms 348 KB Output is correct
21 Correct 3 ms 484 KB Output is correct
22 Correct 4 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 3 ms 452 KB Output is correct
25 Correct 4 ms 452 KB Output is correct
26 Correct 4 ms 344 KB Output is correct
27 Correct 3 ms 348 KB Output is correct
28 Correct 5 ms 348 KB Output is correct
29 Correct 3 ms 348 KB Output is correct
30 Correct 3 ms 348 KB Output is correct
31 Correct 5 ms 348 KB Output is correct
32 Correct 4 ms 348 KB Output is correct
33 Correct 5 ms 348 KB Output is correct
34 Correct 252 ms 576 KB Output is correct
35 Correct 255 ms 600 KB Output is correct
36 Correct 237 ms 572 KB Output is correct
37 Correct 221 ms 348 KB Output is correct
38 Correct 188 ms 580 KB Output is correct
39 Correct 206 ms 596 KB Output is correct
40 Correct 175 ms 564 KB Output is correct
41 Correct 183 ms 560 KB Output is correct
42 Correct 240 ms 348 KB Output is correct
43 Correct 197 ms 348 KB Output is correct
44 Correct 215 ms 572 KB Output is correct
45 Correct 217 ms 576 KB Output is correct
46 Correct 229 ms 600 KB Output is correct
47 Correct 190 ms 596 KB Output is correct
48 Correct 194 ms 588 KB Output is correct
49 Correct 156 ms 564 KB Output is correct
50 Correct 230 ms 600 KB Output is correct
51 Correct 159 ms 604 KB Output is correct
52 Correct 242 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 456 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 5 ms 348 KB Output is correct
15 Correct 5 ms 348 KB Output is correct
16 Correct 5 ms 348 KB Output is correct
17 Correct 5 ms 348 KB Output is correct
18 Correct 3 ms 484 KB Output is correct
19 Correct 4 ms 348 KB Output is correct
20 Correct 4 ms 348 KB Output is correct
21 Correct 3 ms 484 KB Output is correct
22 Correct 4 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 3 ms 452 KB Output is correct
25 Correct 4 ms 452 KB Output is correct
26 Correct 4 ms 344 KB Output is correct
27 Correct 3 ms 348 KB Output is correct
28 Correct 5 ms 348 KB Output is correct
29 Correct 3 ms 348 KB Output is correct
30 Correct 3 ms 348 KB Output is correct
31 Correct 5 ms 348 KB Output is correct
32 Correct 4 ms 348 KB Output is correct
33 Correct 5 ms 348 KB Output is correct
34 Correct 252 ms 576 KB Output is correct
35 Correct 255 ms 600 KB Output is correct
36 Correct 237 ms 572 KB Output is correct
37 Correct 221 ms 348 KB Output is correct
38 Correct 188 ms 580 KB Output is correct
39 Correct 206 ms 596 KB Output is correct
40 Correct 175 ms 564 KB Output is correct
41 Correct 183 ms 560 KB Output is correct
42 Correct 240 ms 348 KB Output is correct
43 Correct 197 ms 348 KB Output is correct
44 Correct 215 ms 572 KB Output is correct
45 Correct 217 ms 576 KB Output is correct
46 Correct 229 ms 600 KB Output is correct
47 Correct 190 ms 596 KB Output is correct
48 Correct 194 ms 588 KB Output is correct
49 Correct 156 ms 564 KB Output is correct
50 Correct 230 ms 600 KB Output is correct
51 Correct 159 ms 604 KB Output is correct
52 Correct 242 ms 600 KB Output is correct
53 Execution timed out 2045 ms 14300 KB Time limit exceeded
54 Halted 0 ms 0 KB -