# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
871534 |
2023-11-11T04:59:03 Z |
resting |
Chorus (JOI23_chorus) |
C++17 |
|
7000 ms |
641616 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
struct segtree{
int l, r, i; double 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(double qm, double 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<double, int> q(int qi){
pair<double, 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++];}
signed main(){
int n, k; cin >> n >> k;
string s; cin >> s;
double l = 1e-7, r = 1e12;
double res = 0, m = 0;
int cnt = 0;
vector<int> b;
for(int i = 0; i < 2*n; i++){
if(s[i] == 'B') b.push_back(i);
}
while(r - l > 1e-6){
if(rand()%2) m = r - (r-l)/100;
else m = sqrt(l*r);
memsz = 0;
segtree ac(0, n);
double sl = 0;
ac.u(0, 0, 0);
int cnta = 0;
double 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++;
}
}
if(cnt <= k) r = m;
else l = m;
}
cout<<(int)round(res-m*k)<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
626576 KB |
Output is correct |
2 |
Correct |
87 ms |
626512 KB |
Output is correct |
3 |
Correct |
84 ms |
626640 KB |
Output is correct |
4 |
Correct |
84 ms |
626516 KB |
Output is correct |
5 |
Correct |
92 ms |
626520 KB |
Output is correct |
6 |
Correct |
85 ms |
626516 KB |
Output is correct |
7 |
Correct |
88 ms |
626516 KB |
Output is correct |
8 |
Correct |
85 ms |
626516 KB |
Output is correct |
9 |
Correct |
84 ms |
626416 KB |
Output is correct |
10 |
Correct |
93 ms |
626432 KB |
Output is correct |
11 |
Correct |
95 ms |
626596 KB |
Output is correct |
12 |
Correct |
85 ms |
626572 KB |
Output is correct |
13 |
Correct |
85 ms |
626516 KB |
Output is correct |
14 |
Correct |
83 ms |
626520 KB |
Output is correct |
15 |
Correct |
83 ms |
626612 KB |
Output is correct |
16 |
Correct |
86 ms |
626512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
626576 KB |
Output is correct |
2 |
Correct |
87 ms |
626512 KB |
Output is correct |
3 |
Correct |
84 ms |
626640 KB |
Output is correct |
4 |
Correct |
84 ms |
626516 KB |
Output is correct |
5 |
Correct |
92 ms |
626520 KB |
Output is correct |
6 |
Correct |
85 ms |
626516 KB |
Output is correct |
7 |
Correct |
88 ms |
626516 KB |
Output is correct |
8 |
Correct |
85 ms |
626516 KB |
Output is correct |
9 |
Correct |
84 ms |
626416 KB |
Output is correct |
10 |
Correct |
93 ms |
626432 KB |
Output is correct |
11 |
Correct |
95 ms |
626596 KB |
Output is correct |
12 |
Correct |
85 ms |
626572 KB |
Output is correct |
13 |
Correct |
85 ms |
626516 KB |
Output is correct |
14 |
Correct |
83 ms |
626520 KB |
Output is correct |
15 |
Correct |
83 ms |
626612 KB |
Output is correct |
16 |
Correct |
86 ms |
626512 KB |
Output is correct |
17 |
Correct |
84 ms |
626500 KB |
Output is correct |
18 |
Correct |
88 ms |
626516 KB |
Output is correct |
19 |
Correct |
87 ms |
626480 KB |
Output is correct |
20 |
Correct |
87 ms |
626416 KB |
Output is correct |
21 |
Correct |
90 ms |
626856 KB |
Output is correct |
22 |
Correct |
86 ms |
626628 KB |
Output is correct |
23 |
Correct |
85 ms |
626512 KB |
Output is correct |
24 |
Correct |
87 ms |
626512 KB |
Output is correct |
25 |
Correct |
87 ms |
626512 KB |
Output is correct |
26 |
Correct |
86 ms |
626512 KB |
Output is correct |
27 |
Correct |
93 ms |
626520 KB |
Output is correct |
28 |
Correct |
89 ms |
626624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
626576 KB |
Output is correct |
2 |
Correct |
87 ms |
626512 KB |
Output is correct |
3 |
Correct |
84 ms |
626640 KB |
Output is correct |
4 |
Correct |
84 ms |
626516 KB |
Output is correct |
5 |
Correct |
92 ms |
626520 KB |
Output is correct |
6 |
Correct |
85 ms |
626516 KB |
Output is correct |
7 |
Correct |
88 ms |
626516 KB |
Output is correct |
8 |
Correct |
85 ms |
626516 KB |
Output is correct |
9 |
Correct |
84 ms |
626416 KB |
Output is correct |
10 |
Correct |
93 ms |
626432 KB |
Output is correct |
11 |
Correct |
95 ms |
626596 KB |
Output is correct |
12 |
Correct |
85 ms |
626572 KB |
Output is correct |
13 |
Correct |
85 ms |
626516 KB |
Output is correct |
14 |
Correct |
83 ms |
626520 KB |
Output is correct |
15 |
Correct |
83 ms |
626612 KB |
Output is correct |
16 |
Correct |
86 ms |
626512 KB |
Output is correct |
17 |
Correct |
84 ms |
626500 KB |
Output is correct |
18 |
Correct |
88 ms |
626516 KB |
Output is correct |
19 |
Correct |
87 ms |
626480 KB |
Output is correct |
20 |
Correct |
87 ms |
626416 KB |
Output is correct |
21 |
Correct |
90 ms |
626856 KB |
Output is correct |
22 |
Correct |
86 ms |
626628 KB |
Output is correct |
23 |
Correct |
85 ms |
626512 KB |
Output is correct |
24 |
Correct |
87 ms |
626512 KB |
Output is correct |
25 |
Correct |
87 ms |
626512 KB |
Output is correct |
26 |
Correct |
86 ms |
626512 KB |
Output is correct |
27 |
Correct |
93 ms |
626520 KB |
Output is correct |
28 |
Correct |
89 ms |
626624 KB |
Output is correct |
29 |
Correct |
133 ms |
626752 KB |
Output is correct |
30 |
Correct |
94 ms |
626756 KB |
Output is correct |
31 |
Correct |
97 ms |
626512 KB |
Output is correct |
32 |
Correct |
136 ms |
626636 KB |
Output is correct |
33 |
Correct |
133 ms |
626512 KB |
Output is correct |
34 |
Correct |
124 ms |
626512 KB |
Output is correct |
35 |
Correct |
97 ms |
626516 KB |
Output is correct |
36 |
Correct |
144 ms |
626532 KB |
Output is correct |
37 |
Correct |
134 ms |
626768 KB |
Output is correct |
38 |
Correct |
119 ms |
626512 KB |
Output is correct |
39 |
Correct |
124 ms |
626512 KB |
Output is correct |
40 |
Correct |
123 ms |
626716 KB |
Output is correct |
41 |
Correct |
124 ms |
626980 KB |
Output is correct |
42 |
Correct |
108 ms |
626508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
626576 KB |
Output is correct |
2 |
Correct |
87 ms |
626512 KB |
Output is correct |
3 |
Correct |
84 ms |
626640 KB |
Output is correct |
4 |
Correct |
84 ms |
626516 KB |
Output is correct |
5 |
Correct |
92 ms |
626520 KB |
Output is correct |
6 |
Correct |
85 ms |
626516 KB |
Output is correct |
7 |
Correct |
88 ms |
626516 KB |
Output is correct |
8 |
Correct |
85 ms |
626516 KB |
Output is correct |
9 |
Correct |
84 ms |
626416 KB |
Output is correct |
10 |
Correct |
93 ms |
626432 KB |
Output is correct |
11 |
Correct |
95 ms |
626596 KB |
Output is correct |
12 |
Correct |
85 ms |
626572 KB |
Output is correct |
13 |
Correct |
85 ms |
626516 KB |
Output is correct |
14 |
Correct |
83 ms |
626520 KB |
Output is correct |
15 |
Correct |
83 ms |
626612 KB |
Output is correct |
16 |
Correct |
86 ms |
626512 KB |
Output is correct |
17 |
Correct |
84 ms |
626500 KB |
Output is correct |
18 |
Correct |
88 ms |
626516 KB |
Output is correct |
19 |
Correct |
87 ms |
626480 KB |
Output is correct |
20 |
Correct |
87 ms |
626416 KB |
Output is correct |
21 |
Correct |
90 ms |
626856 KB |
Output is correct |
22 |
Correct |
86 ms |
626628 KB |
Output is correct |
23 |
Correct |
85 ms |
626512 KB |
Output is correct |
24 |
Correct |
87 ms |
626512 KB |
Output is correct |
25 |
Correct |
87 ms |
626512 KB |
Output is correct |
26 |
Correct |
86 ms |
626512 KB |
Output is correct |
27 |
Correct |
93 ms |
626520 KB |
Output is correct |
28 |
Correct |
89 ms |
626624 KB |
Output is correct |
29 |
Correct |
133 ms |
626752 KB |
Output is correct |
30 |
Correct |
94 ms |
626756 KB |
Output is correct |
31 |
Correct |
97 ms |
626512 KB |
Output is correct |
32 |
Correct |
136 ms |
626636 KB |
Output is correct |
33 |
Correct |
133 ms |
626512 KB |
Output is correct |
34 |
Correct |
124 ms |
626512 KB |
Output is correct |
35 |
Correct |
97 ms |
626516 KB |
Output is correct |
36 |
Correct |
144 ms |
626532 KB |
Output is correct |
37 |
Correct |
134 ms |
626768 KB |
Output is correct |
38 |
Correct |
119 ms |
626512 KB |
Output is correct |
39 |
Correct |
124 ms |
626512 KB |
Output is correct |
40 |
Correct |
123 ms |
626716 KB |
Output is correct |
41 |
Correct |
124 ms |
626980 KB |
Output is correct |
42 |
Correct |
108 ms |
626508 KB |
Output is correct |
43 |
Correct |
227 ms |
627292 KB |
Output is correct |
44 |
Correct |
840 ms |
627796 KB |
Output is correct |
45 |
Correct |
342 ms |
627804 KB |
Output is correct |
46 |
Correct |
1484 ms |
627800 KB |
Output is correct |
47 |
Correct |
1219 ms |
627812 KB |
Output is correct |
48 |
Correct |
871 ms |
627828 KB |
Output is correct |
49 |
Correct |
315 ms |
627908 KB |
Output is correct |
50 |
Correct |
1832 ms |
627904 KB |
Output is correct |
51 |
Correct |
1553 ms |
627804 KB |
Output is correct |
52 |
Correct |
320 ms |
627804 KB |
Output is correct |
53 |
Correct |
830 ms |
627784 KB |
Output is correct |
54 |
Correct |
1394 ms |
627752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
626576 KB |
Output is correct |
2 |
Correct |
87 ms |
626512 KB |
Output is correct |
3 |
Correct |
84 ms |
626640 KB |
Output is correct |
4 |
Correct |
84 ms |
626516 KB |
Output is correct |
5 |
Correct |
92 ms |
626520 KB |
Output is correct |
6 |
Correct |
85 ms |
626516 KB |
Output is correct |
7 |
Correct |
88 ms |
626516 KB |
Output is correct |
8 |
Correct |
85 ms |
626516 KB |
Output is correct |
9 |
Correct |
84 ms |
626416 KB |
Output is correct |
10 |
Correct |
93 ms |
626432 KB |
Output is correct |
11 |
Correct |
95 ms |
626596 KB |
Output is correct |
12 |
Correct |
85 ms |
626572 KB |
Output is correct |
13 |
Correct |
85 ms |
626516 KB |
Output is correct |
14 |
Correct |
83 ms |
626520 KB |
Output is correct |
15 |
Correct |
83 ms |
626612 KB |
Output is correct |
16 |
Correct |
86 ms |
626512 KB |
Output is correct |
17 |
Correct |
84 ms |
626500 KB |
Output is correct |
18 |
Correct |
88 ms |
626516 KB |
Output is correct |
19 |
Correct |
87 ms |
626480 KB |
Output is correct |
20 |
Correct |
87 ms |
626416 KB |
Output is correct |
21 |
Correct |
90 ms |
626856 KB |
Output is correct |
22 |
Correct |
86 ms |
626628 KB |
Output is correct |
23 |
Correct |
85 ms |
626512 KB |
Output is correct |
24 |
Correct |
87 ms |
626512 KB |
Output is correct |
25 |
Correct |
87 ms |
626512 KB |
Output is correct |
26 |
Correct |
86 ms |
626512 KB |
Output is correct |
27 |
Correct |
93 ms |
626520 KB |
Output is correct |
28 |
Correct |
89 ms |
626624 KB |
Output is correct |
29 |
Correct |
133 ms |
626752 KB |
Output is correct |
30 |
Correct |
94 ms |
626756 KB |
Output is correct |
31 |
Correct |
97 ms |
626512 KB |
Output is correct |
32 |
Correct |
136 ms |
626636 KB |
Output is correct |
33 |
Correct |
133 ms |
626512 KB |
Output is correct |
34 |
Correct |
124 ms |
626512 KB |
Output is correct |
35 |
Correct |
97 ms |
626516 KB |
Output is correct |
36 |
Correct |
144 ms |
626532 KB |
Output is correct |
37 |
Correct |
134 ms |
626768 KB |
Output is correct |
38 |
Correct |
119 ms |
626512 KB |
Output is correct |
39 |
Correct |
124 ms |
626512 KB |
Output is correct |
40 |
Correct |
123 ms |
626716 KB |
Output is correct |
41 |
Correct |
124 ms |
626980 KB |
Output is correct |
42 |
Correct |
108 ms |
626508 KB |
Output is correct |
43 |
Correct |
227 ms |
627292 KB |
Output is correct |
44 |
Correct |
840 ms |
627796 KB |
Output is correct |
45 |
Correct |
342 ms |
627804 KB |
Output is correct |
46 |
Correct |
1484 ms |
627800 KB |
Output is correct |
47 |
Correct |
1219 ms |
627812 KB |
Output is correct |
48 |
Correct |
871 ms |
627828 KB |
Output is correct |
49 |
Correct |
315 ms |
627908 KB |
Output is correct |
50 |
Correct |
1832 ms |
627904 KB |
Output is correct |
51 |
Correct |
1553 ms |
627804 KB |
Output is correct |
52 |
Correct |
320 ms |
627804 KB |
Output is correct |
53 |
Correct |
830 ms |
627784 KB |
Output is correct |
54 |
Correct |
1394 ms |
627752 KB |
Output is correct |
55 |
Correct |
1950 ms |
637508 KB |
Output is correct |
56 |
Correct |
2994 ms |
640576 KB |
Output is correct |
57 |
Correct |
3017 ms |
641616 KB |
Output is correct |
58 |
Execution timed out |
7008 ms |
640440 KB |
Time limit exceeded |
59 |
Halted |
0 ms |
0 KB |
- |