답안 #871555

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
871555 2023-11-11T05:39:32 Z resting Chorus (JOI23_chorus) C++17
87 / 100
3776 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

struct segtree{
    int l, r, i; int m, b; int cnt;
    segtree* lc = 0, *rc = 0;
    segtree* getmem();
    segtree(int l, int r) : l(l), r(r), m(0), b(1e9), cnt(0){
        i = (l + r) / 2;
        if(l==r) return;
        lc = getmem(); *lc = segtree(l, i);
        rc = getmem(); *rc = segtree(i+1, r);
    };
    segtree() : segtree(-1, -1){};
    void u(int qm, int qb, int qcnt){
        if(qm * i + qb < m*i+b){
            swap(m, qm); swap(b, qb); swap(cnt, qcnt);
        }
        if(l == r) return;
        if(qm > m) lc->u(qm, qb, qcnt);
        else rc->u(qm, qb, qcnt);
    }
    pair<int, int> q(int qi){
        pair<int, int> cur = {m*qi+b, cnt};
        if(i == qi) return cur;
        if(qi < i) return min(cur, lc->q(qi));
        else return min(cur, rc->q(qi));
    }

} mem[(int)1e7]; int memsz = 0; 
segtree* segtree::getmem(){return &mem[memsz++];}
int n, k; 
int res = 0;
int cnt = 0;string s; 
vector<int> b;
void solve(int m){
    segtree ac(0, n);
    int sl = 0;
    ac.u(0, 0, 0);
    int cnta = 0;
    int cur = 0;
    int funnynumber = 0;
    int cntactive = 0;
    for(int i = 0; i < 2 * n; i++){
        if(s[i] == 'A'){
            if(cntactive>0) funnynumber -= cntactive;
            cntactive++;
            if(cntactive>0) funnynumber += b[cnta] - i - cntactive;
            cnta++;
            cur += sl;
            auto tmp = ac.q(cnta); 
            tmp.first += m; tmp.second++;
            if(cnta == n) {
                res = tmp.first + cur;
                cnt = tmp.second;
            }
            ac.u(-cnta, tmp.first + (cnta)*cnta+funnynumber, tmp.second);
        }
        else{
            cntactive--;
            sl++;
        }
    }
}
signed main(){
    cin >> n >> k;
    cin >> s;
    int l = -1, r = 2e12;
    int m = 0; 
    for(int i = 0; i < 2*n; i++){
        if(s[i] == 'B') b.push_back(i);
    }
    while(r - l > 1){
        m = (l+r)/2;
        solve(m);
        if(cnt <= k) r = m;
        else l = m;
    }
    solve(r);
    cout<<res-k*r<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 626608 KB Output is correct
2 Correct 86 ms 626512 KB Output is correct
3 Correct 86 ms 626516 KB Output is correct
4 Correct 84 ms 626516 KB Output is correct
5 Correct 86 ms 626528 KB Output is correct
6 Correct 85 ms 626516 KB Output is correct
7 Correct 85 ms 626444 KB Output is correct
8 Correct 92 ms 626412 KB Output is correct
9 Correct 86 ms 626512 KB Output is correct
10 Correct 85 ms 626516 KB Output is correct
11 Correct 89 ms 626664 KB Output is correct
12 Correct 86 ms 626516 KB Output is correct
13 Correct 85 ms 626512 KB Output is correct
14 Correct 85 ms 626624 KB Output is correct
15 Correct 85 ms 626512 KB Output is correct
16 Correct 90 ms 626580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 626608 KB Output is correct
2 Correct 86 ms 626512 KB Output is correct
3 Correct 86 ms 626516 KB Output is correct
4 Correct 84 ms 626516 KB Output is correct
5 Correct 86 ms 626528 KB Output is correct
6 Correct 85 ms 626516 KB Output is correct
7 Correct 85 ms 626444 KB Output is correct
8 Correct 92 ms 626412 KB Output is correct
9 Correct 86 ms 626512 KB Output is correct
10 Correct 85 ms 626516 KB Output is correct
11 Correct 89 ms 626664 KB Output is correct
12 Correct 86 ms 626516 KB Output is correct
13 Correct 85 ms 626512 KB Output is correct
14 Correct 85 ms 626624 KB Output is correct
15 Correct 85 ms 626512 KB Output is correct
16 Correct 90 ms 626580 KB Output is correct
17 Correct 87 ms 626436 KB Output is correct
18 Correct 87 ms 626644 KB Output is correct
19 Correct 86 ms 626516 KB Output is correct
20 Correct 95 ms 626596 KB Output is correct
21 Correct 86 ms 626440 KB Output is correct
22 Correct 87 ms 626456 KB Output is correct
23 Correct 88 ms 626524 KB Output is correct
24 Correct 92 ms 626416 KB Output is correct
25 Correct 87 ms 626584 KB Output is correct
26 Correct 90 ms 626512 KB Output is correct
27 Correct 87 ms 626516 KB Output is correct
28 Correct 87 ms 626720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 626608 KB Output is correct
2 Correct 86 ms 626512 KB Output is correct
3 Correct 86 ms 626516 KB Output is correct
4 Correct 84 ms 626516 KB Output is correct
5 Correct 86 ms 626528 KB Output is correct
6 Correct 85 ms 626516 KB Output is correct
7 Correct 85 ms 626444 KB Output is correct
8 Correct 92 ms 626412 KB Output is correct
9 Correct 86 ms 626512 KB Output is correct
10 Correct 85 ms 626516 KB Output is correct
11 Correct 89 ms 626664 KB Output is correct
12 Correct 86 ms 626516 KB Output is correct
13 Correct 85 ms 626512 KB Output is correct
14 Correct 85 ms 626624 KB Output is correct
15 Correct 85 ms 626512 KB Output is correct
16 Correct 90 ms 626580 KB Output is correct
17 Correct 87 ms 626436 KB Output is correct
18 Correct 87 ms 626644 KB Output is correct
19 Correct 86 ms 626516 KB Output is correct
20 Correct 95 ms 626596 KB Output is correct
21 Correct 86 ms 626440 KB Output is correct
22 Correct 87 ms 626456 KB Output is correct
23 Correct 88 ms 626524 KB Output is correct
24 Correct 92 ms 626416 KB Output is correct
25 Correct 87 ms 626584 KB Output is correct
26 Correct 90 ms 626512 KB Output is correct
27 Correct 87 ms 626516 KB Output is correct
28 Correct 87 ms 626720 KB Output is correct
29 Correct 116 ms 626648 KB Output is correct
30 Correct 116 ms 626520 KB Output is correct
31 Correct 115 ms 626516 KB Output is correct
32 Correct 110 ms 626512 KB Output is correct
33 Correct 120 ms 626512 KB Output is correct
34 Correct 113 ms 626660 KB Output is correct
35 Correct 110 ms 626568 KB Output is correct
36 Correct 117 ms 626752 KB Output is correct
37 Correct 119 ms 626612 KB Output is correct
38 Correct 112 ms 626540 KB Output is correct
39 Correct 126 ms 626516 KB Output is correct
40 Correct 115 ms 626516 KB Output is correct
41 Correct 116 ms 627024 KB Output is correct
42 Correct 108 ms 626516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 626608 KB Output is correct
2 Correct 86 ms 626512 KB Output is correct
3 Correct 86 ms 626516 KB Output is correct
4 Correct 84 ms 626516 KB Output is correct
5 Correct 86 ms 626528 KB Output is correct
6 Correct 85 ms 626516 KB Output is correct
7 Correct 85 ms 626444 KB Output is correct
8 Correct 92 ms 626412 KB Output is correct
9 Correct 86 ms 626512 KB Output is correct
10 Correct 85 ms 626516 KB Output is correct
11 Correct 89 ms 626664 KB Output is correct
12 Correct 86 ms 626516 KB Output is correct
13 Correct 85 ms 626512 KB Output is correct
14 Correct 85 ms 626624 KB Output is correct
15 Correct 85 ms 626512 KB Output is correct
16 Correct 90 ms 626580 KB Output is correct
17 Correct 87 ms 626436 KB Output is correct
18 Correct 87 ms 626644 KB Output is correct
19 Correct 86 ms 626516 KB Output is correct
20 Correct 95 ms 626596 KB Output is correct
21 Correct 86 ms 626440 KB Output is correct
22 Correct 87 ms 626456 KB Output is correct
23 Correct 88 ms 626524 KB Output is correct
24 Correct 92 ms 626416 KB Output is correct
25 Correct 87 ms 626584 KB Output is correct
26 Correct 90 ms 626512 KB Output is correct
27 Correct 87 ms 626516 KB Output is correct
28 Correct 87 ms 626720 KB Output is correct
29 Correct 116 ms 626648 KB Output is correct
30 Correct 116 ms 626520 KB Output is correct
31 Correct 115 ms 626516 KB Output is correct
32 Correct 110 ms 626512 KB Output is correct
33 Correct 120 ms 626512 KB Output is correct
34 Correct 113 ms 626660 KB Output is correct
35 Correct 110 ms 626568 KB Output is correct
36 Correct 117 ms 626752 KB Output is correct
37 Correct 119 ms 626612 KB Output is correct
38 Correct 112 ms 626540 KB Output is correct
39 Correct 126 ms 626516 KB Output is correct
40 Correct 115 ms 626516 KB Output is correct
41 Correct 116 ms 627024 KB Output is correct
42 Correct 108 ms 626516 KB Output is correct
43 Correct 536 ms 627408 KB Output is correct
44 Correct 904 ms 627884 KB Output is correct
45 Correct 913 ms 627944 KB Output is correct
46 Correct 701 ms 627872 KB Output is correct
47 Correct 728 ms 627848 KB Output is correct
48 Correct 868 ms 628052 KB Output is correct
49 Correct 855 ms 628560 KB Output is correct
50 Correct 922 ms 627928 KB Output is correct
51 Correct 955 ms 627892 KB Output is correct
52 Correct 869 ms 627804 KB Output is correct
53 Correct 896 ms 627804 KB Output is correct
54 Correct 969 ms 628136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 626608 KB Output is correct
2 Correct 86 ms 626512 KB Output is correct
3 Correct 86 ms 626516 KB Output is correct
4 Correct 84 ms 626516 KB Output is correct
5 Correct 86 ms 626528 KB Output is correct
6 Correct 85 ms 626516 KB Output is correct
7 Correct 85 ms 626444 KB Output is correct
8 Correct 92 ms 626412 KB Output is correct
9 Correct 86 ms 626512 KB Output is correct
10 Correct 85 ms 626516 KB Output is correct
11 Correct 89 ms 626664 KB Output is correct
12 Correct 86 ms 626516 KB Output is correct
13 Correct 85 ms 626512 KB Output is correct
14 Correct 85 ms 626624 KB Output is correct
15 Correct 85 ms 626512 KB Output is correct
16 Correct 90 ms 626580 KB Output is correct
17 Correct 87 ms 626436 KB Output is correct
18 Correct 87 ms 626644 KB Output is correct
19 Correct 86 ms 626516 KB Output is correct
20 Correct 95 ms 626596 KB Output is correct
21 Correct 86 ms 626440 KB Output is correct
22 Correct 87 ms 626456 KB Output is correct
23 Correct 88 ms 626524 KB Output is correct
24 Correct 92 ms 626416 KB Output is correct
25 Correct 87 ms 626584 KB Output is correct
26 Correct 90 ms 626512 KB Output is correct
27 Correct 87 ms 626516 KB Output is correct
28 Correct 87 ms 626720 KB Output is correct
29 Correct 116 ms 626648 KB Output is correct
30 Correct 116 ms 626520 KB Output is correct
31 Correct 115 ms 626516 KB Output is correct
32 Correct 110 ms 626512 KB Output is correct
33 Correct 120 ms 626512 KB Output is correct
34 Correct 113 ms 626660 KB Output is correct
35 Correct 110 ms 626568 KB Output is correct
36 Correct 117 ms 626752 KB Output is correct
37 Correct 119 ms 626612 KB Output is correct
38 Correct 112 ms 626540 KB Output is correct
39 Correct 126 ms 626516 KB Output is correct
40 Correct 115 ms 626516 KB Output is correct
41 Correct 116 ms 627024 KB Output is correct
42 Correct 108 ms 626516 KB Output is correct
43 Correct 536 ms 627408 KB Output is correct
44 Correct 904 ms 627884 KB Output is correct
45 Correct 913 ms 627944 KB Output is correct
46 Correct 701 ms 627872 KB Output is correct
47 Correct 728 ms 627848 KB Output is correct
48 Correct 868 ms 628052 KB Output is correct
49 Correct 855 ms 628560 KB Output is correct
50 Correct 922 ms 627928 KB Output is correct
51 Correct 955 ms 627892 KB Output is correct
52 Correct 869 ms 627804 KB Output is correct
53 Correct 896 ms 627804 KB Output is correct
54 Correct 969 ms 628136 KB Output is correct
55 Runtime error 3776 ms 1048576 KB Execution killed with signal 9
56 Halted 0 ms 0 KB -