# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
788563 |
2023-07-20T11:04:31 Z |
someone |
Chorus (JOI23_chorus) |
C++14 |
|
12 ms |
1620 KB |
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 5e3 + 42, INF = 1e12 + 42;
vector<int> pre, upd[N];
deque<int> imin, a, b, c;
int n, k, cumul[N], fi[N], dp[N], nbT[N];
int evalCHT(int x) {
while((int)a.size() >= 2 && (a[0] * x + b[0] > a[1] * x + b[1] || (a[0] * x + b[0] == a[1] * x + b[1] && c[0] >= c[1]))) {
a.pop_front();
b.pop_front();
c.pop_front();
}
return a[0] * x + b[0];
}
void pushCHT(int A, int B, int C) {
int sz = (int)a.size();
while(sz >= 2 && (B - b[sz-1]) * (a[sz-2] - a[sz-1]) <= (b[sz-1] - b[sz-2]) * (a[sz-1] - A)) {
sz--;
a.pop_back();
b.pop_back();
c.pop_back();
}
a.push_back(A);
b.push_back(B);
c.push_back(C);
}
void add(int i) {
if(fi[i] == i) {
pushCHT(-i, dp[i] + i * fi[i] - cumul[fi[i]], nbT[i]);
return;
}
upd[fi[i]].push_back(i);
while(!imin.empty() && (dp[imin.back()] > dp[i] || (dp[imin.back()] == dp[i] && nbT[imin.back()] > nbT[i])))
imin.pop_back();
imin.push_back(i);
}
pair<int, int> solve(int lambda) {
a.clear();
b.clear();
c.clear();
imin.clear();
for(int i = 0; i < N; i++)
upd[i].clear();
add(0);
for(int i = 1; i <= n; i++) {
for(int j : upd[i]) {
pushCHT(-j, dp[j] + j * fi[j] - cumul[fi[j]], nbT[j]);
if(!imin.empty() && imin[0] == j)
imin.pop_front();
}
dp[i] = evalCHT(i) + cumul[i];
nbT[i] = c[0];
if(!imin.empty())
if(dp[imin[0]] < dp[i] || (dp[imin[0]] == dp[i] && nbT[imin[0]] < dp[i]))
nbT[i] = nbT[imin[0]];
nbT[i]++;
dp[i] += lambda;
add(i);
}
return {dp[n], nbT[n]};
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int x = 0;
cin >> n >> k;
for(int i = 0; i < N; i++)
fi[i] = N-1;
pre.clear();
int nbA = 0;
for(int i = 0; i < 2*n; i++) {
char ch; cin >> ch;
if(ch == 'A') {
nbA++;
if(fi[x] == N-1)
fi[x] = (int)pre.size();
pre.push_back(x);
} else {
x++;
}
}
for(int i = n-1; i > -1; i--)
if(fi[i] == N-1)
fi[i] = fi[i+1];
for(int i = 0; i <= n; i++)
fi[i] = max(fi[i], i);
for(int i = 1; i <= n; i++)
cumul[i] = cumul[i-1] + pre[i-1];
int deb = 0, fin = INF;
while(fin - deb > 1) {
int mid = ((deb + fin) >> 1);
auto pii = solve(mid-1);
if(pii.second <= k)
fin = mid;
else
deb = mid;
}
cout << solve(deb).first - k * deb << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
448 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
452 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
448 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
452 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
448 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
452 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
8 ms |
724 KB |
Output is correct |
30 |
Correct |
11 ms |
792 KB |
Output is correct |
31 |
Correct |
11 ms |
784 KB |
Output is correct |
32 |
Correct |
6 ms |
716 KB |
Output is correct |
33 |
Correct |
7 ms |
744 KB |
Output is correct |
34 |
Correct |
7 ms |
596 KB |
Output is correct |
35 |
Correct |
7 ms |
712 KB |
Output is correct |
36 |
Correct |
12 ms |
724 KB |
Output is correct |
37 |
Correct |
11 ms |
744 KB |
Output is correct |
38 |
Correct |
7 ms |
724 KB |
Output is correct |
39 |
Correct |
9 ms |
724 KB |
Output is correct |
40 |
Correct |
7 ms |
724 KB |
Output is correct |
41 |
Correct |
7 ms |
724 KB |
Output is correct |
42 |
Correct |
5 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
448 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
452 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
8 ms |
724 KB |
Output is correct |
30 |
Correct |
11 ms |
792 KB |
Output is correct |
31 |
Correct |
11 ms |
784 KB |
Output is correct |
32 |
Correct |
6 ms |
716 KB |
Output is correct |
33 |
Correct |
7 ms |
744 KB |
Output is correct |
34 |
Correct |
7 ms |
596 KB |
Output is correct |
35 |
Correct |
7 ms |
712 KB |
Output is correct |
36 |
Correct |
12 ms |
724 KB |
Output is correct |
37 |
Correct |
11 ms |
744 KB |
Output is correct |
38 |
Correct |
7 ms |
724 KB |
Output is correct |
39 |
Correct |
9 ms |
724 KB |
Output is correct |
40 |
Correct |
7 ms |
724 KB |
Output is correct |
41 |
Correct |
7 ms |
724 KB |
Output is correct |
42 |
Correct |
5 ms |
724 KB |
Output is correct |
43 |
Runtime error |
3 ms |
1620 KB |
Execution killed with signal 11 |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
448 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
452 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
8 ms |
724 KB |
Output is correct |
30 |
Correct |
11 ms |
792 KB |
Output is correct |
31 |
Correct |
11 ms |
784 KB |
Output is correct |
32 |
Correct |
6 ms |
716 KB |
Output is correct |
33 |
Correct |
7 ms |
744 KB |
Output is correct |
34 |
Correct |
7 ms |
596 KB |
Output is correct |
35 |
Correct |
7 ms |
712 KB |
Output is correct |
36 |
Correct |
12 ms |
724 KB |
Output is correct |
37 |
Correct |
11 ms |
744 KB |
Output is correct |
38 |
Correct |
7 ms |
724 KB |
Output is correct |
39 |
Correct |
9 ms |
724 KB |
Output is correct |
40 |
Correct |
7 ms |
724 KB |
Output is correct |
41 |
Correct |
7 ms |
724 KB |
Output is correct |
42 |
Correct |
5 ms |
724 KB |
Output is correct |
43 |
Runtime error |
3 ms |
1620 KB |
Execution killed with signal 11 |
44 |
Halted |
0 ms |
0 KB |
- |