# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
1037763 |
2024-07-29T08:01:06 Z |
ㅇㅇ(223.39)(#11011) |
Chorus (JOI23_chorus) |
C++17 |
|
7000 ms |
6036 KB |
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
using ll=long long;
using db=double;
using pll=array<ll,2>;
using tll=array<ll,3>;
const ll inf=1e18;
const int N=1000005;
int n,k,a[N],m,f[N];
string s;
ll S[N];
pll dp[N];
ll base,ans;
struct ConvexHullTrick{
tll L[N];
int sz,p;
db cross(tll a,tll b){
return (db)(b[1]-a[1])/(a[0]-b[0]);
}
void add_line(tll l){
while(sz>=2&&cross(L[sz-1],L[sz])>=cross(L[sz],l)) sz--;
L[++sz]=l;
p=min(p,sz);
}
pll qry(ll x){
if(!sz) return {-1,-1};
while(p<sz&&cross(L[p],L[p+1])<=x) p++;
return {L[p][0]*x+L[p][1],L[p][2]};
}
}CHT;
pll Do(ll C){
dp[0]={0,0};
deque<int> dq;
dq.push_back(0);
CHT.sz=0; CHT.p=1;
for(int i=1;i<=n;i++){
dp[i]={inf,inf};
/*while(dq.size()&&dq.front()<=f[i]-2) dq.pop_front();
if(dq.size()) dp[i]={dp[dq.front()][0]+C,dp[dq.front()][1]+1};
for(int j=max(0,f[i-1]-1);j<=f[i]-2;j++) CHT.add_line({-j,dp[j][0]-(ll)j*(j+1)/2+S[j]+C,dp[j][1]+1});
pll Q=CHT.qry(i);
if(Q[1]!=-1) dp[i]=min(dp[i],{Q[0]+(ll)(f[i]-1)*i+(ll)(i-1)*i/2-S[f[i]-1],Q[1]});
while(dq.size()&&dp[dq.back()]>=dp[i]) dq.pop_back();
dq.push_back(i);*/
ll s=0;
for(int j=i;j>=1;j--){
s+=max(0,i+j-a[j]);
dp[i]=min(dp[i],{dp[j-1][0]+s+C,dp[j-1][1]+1});
}
debug(C,i,dp[i]);
}
return dp[n];
}
int main(){
ios::sync_with_stdio(false); cin.tie(0);
cin>>n>>k>>s;
for(int i=1;i<=2*n;i++) if(s[i-1]=='B') a[++m]=i;
for(int i=1;i<=n;i++) if(a[i]<2*i){
base+=2*i-a[i];
a[i]=2*i;
}
for(int i=1;i<=n;i++) S[i]=S[i-1]+a[i];
f[1]=1;
for(int i=2;i<=n;i++){
f[i]=f[i-1];
while(i+f[i]-a[f[i]]>0) f[i]++;
}
ll L=-1e10,R=1e10;
while(L<=R){
ll M=(L+R)>>1;
auto [dp,cnt]=Do(M);
ans=max(ans,dp-k*M);
if(cnt<=k) R=M-1;
else L=M+1;
}
cout<<base+ans;
return 0;
}
Compilation message
chorus.cpp: In function 'pll Do(ll)':
chorus.cpp:9:20: warning: statement has no effect [-Wunused-value]
9 | #define debug(...) 42
| ^~
chorus.cpp:58:3: note: in expansion of macro 'debug'
58 | debug(C,i,dp[i]);
| ^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2484 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2484 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
2 ms |
2396 KB |
Output is correct |
18 |
Correct |
17 ms |
2396 KB |
Output is correct |
19 |
Correct |
10 ms |
2396 KB |
Output is correct |
20 |
Correct |
20 ms |
2396 KB |
Output is correct |
21 |
Correct |
21 ms |
2396 KB |
Output is correct |
22 |
Correct |
17 ms |
2396 KB |
Output is correct |
23 |
Correct |
9 ms |
2396 KB |
Output is correct |
24 |
Correct |
18 ms |
2552 KB |
Output is correct |
25 |
Correct |
9 ms |
2556 KB |
Output is correct |
26 |
Correct |
17 ms |
2556 KB |
Output is correct |
27 |
Correct |
17 ms |
2552 KB |
Output is correct |
28 |
Correct |
17 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2484 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
2 ms |
2396 KB |
Output is correct |
18 |
Correct |
17 ms |
2396 KB |
Output is correct |
19 |
Correct |
10 ms |
2396 KB |
Output is correct |
20 |
Correct |
20 ms |
2396 KB |
Output is correct |
21 |
Correct |
21 ms |
2396 KB |
Output is correct |
22 |
Correct |
17 ms |
2396 KB |
Output is correct |
23 |
Correct |
9 ms |
2396 KB |
Output is correct |
24 |
Correct |
18 ms |
2552 KB |
Output is correct |
25 |
Correct |
9 ms |
2556 KB |
Output is correct |
26 |
Correct |
17 ms |
2556 KB |
Output is correct |
27 |
Correct |
17 ms |
2552 KB |
Output is correct |
28 |
Correct |
17 ms |
2396 KB |
Output is correct |
29 |
Correct |
1287 ms |
4700 KB |
Output is correct |
30 |
Correct |
880 ms |
4724 KB |
Output is correct |
31 |
Correct |
872 ms |
4720 KB |
Output is correct |
32 |
Correct |
2033 ms |
4700 KB |
Output is correct |
33 |
Correct |
1724 ms |
4700 KB |
Output is correct |
34 |
Correct |
1226 ms |
4700 KB |
Output is correct |
35 |
Correct |
780 ms |
4720 KB |
Output is correct |
36 |
Correct |
1453 ms |
4572 KB |
Output is correct |
37 |
Correct |
1367 ms |
4724 KB |
Output is correct |
38 |
Correct |
1349 ms |
4724 KB |
Output is correct |
39 |
Correct |
1296 ms |
4724 KB |
Output is correct |
40 |
Correct |
1323 ms |
4700 KB |
Output is correct |
41 |
Correct |
1370 ms |
4716 KB |
Output is correct |
42 |
Correct |
1469 ms |
4724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2484 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
2 ms |
2396 KB |
Output is correct |
18 |
Correct |
17 ms |
2396 KB |
Output is correct |
19 |
Correct |
10 ms |
2396 KB |
Output is correct |
20 |
Correct |
20 ms |
2396 KB |
Output is correct |
21 |
Correct |
21 ms |
2396 KB |
Output is correct |
22 |
Correct |
17 ms |
2396 KB |
Output is correct |
23 |
Correct |
9 ms |
2396 KB |
Output is correct |
24 |
Correct |
18 ms |
2552 KB |
Output is correct |
25 |
Correct |
9 ms |
2556 KB |
Output is correct |
26 |
Correct |
17 ms |
2556 KB |
Output is correct |
27 |
Correct |
17 ms |
2552 KB |
Output is correct |
28 |
Correct |
17 ms |
2396 KB |
Output is correct |
29 |
Correct |
1287 ms |
4700 KB |
Output is correct |
30 |
Correct |
880 ms |
4724 KB |
Output is correct |
31 |
Correct |
872 ms |
4720 KB |
Output is correct |
32 |
Correct |
2033 ms |
4700 KB |
Output is correct |
33 |
Correct |
1724 ms |
4700 KB |
Output is correct |
34 |
Correct |
1226 ms |
4700 KB |
Output is correct |
35 |
Correct |
780 ms |
4720 KB |
Output is correct |
36 |
Correct |
1453 ms |
4572 KB |
Output is correct |
37 |
Correct |
1367 ms |
4724 KB |
Output is correct |
38 |
Correct |
1349 ms |
4724 KB |
Output is correct |
39 |
Correct |
1296 ms |
4724 KB |
Output is correct |
40 |
Correct |
1323 ms |
4700 KB |
Output is correct |
41 |
Correct |
1370 ms |
4716 KB |
Output is correct |
42 |
Correct |
1469 ms |
4724 KB |
Output is correct |
43 |
Execution timed out |
7029 ms |
6036 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2484 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
2 ms |
2396 KB |
Output is correct |
18 |
Correct |
17 ms |
2396 KB |
Output is correct |
19 |
Correct |
10 ms |
2396 KB |
Output is correct |
20 |
Correct |
20 ms |
2396 KB |
Output is correct |
21 |
Correct |
21 ms |
2396 KB |
Output is correct |
22 |
Correct |
17 ms |
2396 KB |
Output is correct |
23 |
Correct |
9 ms |
2396 KB |
Output is correct |
24 |
Correct |
18 ms |
2552 KB |
Output is correct |
25 |
Correct |
9 ms |
2556 KB |
Output is correct |
26 |
Correct |
17 ms |
2556 KB |
Output is correct |
27 |
Correct |
17 ms |
2552 KB |
Output is correct |
28 |
Correct |
17 ms |
2396 KB |
Output is correct |
29 |
Correct |
1287 ms |
4700 KB |
Output is correct |
30 |
Correct |
880 ms |
4724 KB |
Output is correct |
31 |
Correct |
872 ms |
4720 KB |
Output is correct |
32 |
Correct |
2033 ms |
4700 KB |
Output is correct |
33 |
Correct |
1724 ms |
4700 KB |
Output is correct |
34 |
Correct |
1226 ms |
4700 KB |
Output is correct |
35 |
Correct |
780 ms |
4720 KB |
Output is correct |
36 |
Correct |
1453 ms |
4572 KB |
Output is correct |
37 |
Correct |
1367 ms |
4724 KB |
Output is correct |
38 |
Correct |
1349 ms |
4724 KB |
Output is correct |
39 |
Correct |
1296 ms |
4724 KB |
Output is correct |
40 |
Correct |
1323 ms |
4700 KB |
Output is correct |
41 |
Correct |
1370 ms |
4716 KB |
Output is correct |
42 |
Correct |
1469 ms |
4724 KB |
Output is correct |
43 |
Execution timed out |
7029 ms |
6036 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |