# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
741494 | 2023-05-14T08:59:49 Z | arnold518 | Chorus (JOI23_chorus) | C++17 | 1 ms | 340 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1e6; const ll INF = 1e12; int N, K; char S[MAXN*2+10]; int A[MAXN+10], C[MAXN+10]; ll B[MAXN+10]; ll ans; ll f(int l, int r) { if(C[r]<l) return 0; return (ll)r*(C[r]-l+1)-(B[C[r]]-B[l-1]); } pll dp[MAXN+10]; ll solve(ll lambda) { dp[0]={0, 0}; deque<int> DQ; DQ.push_back(0); for(int i=1; i<=N; i++) { while(DQ.size()>1 && dp[DQ[0]].first+lambda+2*f(DQ[0]+1, i)>=dp[DQ[1]].first+lambda+2*f(DQ[1]+1, i)) DQ.pop_front(); dp[i]={dp[DQ.front()].first+lambda+2*f(DQ.front()+1, i), dp[DQ.front()].second+1}; DQ.push_back(i); } return dp[N].second; } int main() { scanf("%d%d", &N, &K); scanf(" %s", S+1); int t=0, k=0; for(int i=1; i<=N+N; i++) { if(S[i]=='A') k++; else A[++t]=k; } for(int i=1; i<=N; i++) { if(A[i]<i) { ans+=i-A[i]; A[i]=i; } B[i]=B[i-1]+A[i]; } for(int i=1, j=1; i<=N; i++) { for(; j<=N && A[j]<i; j++); C[i]=j-1; } ll lo=-1, hi=INF; while(lo+1<hi) { ll mid=lo+hi>>1; if(solve(mid*2+1)<K) hi=mid; else lo=mid; } solve(hi*2); printf("%lld\n", ans+dp[N].first/2-K*hi); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 340 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 340 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 0 ms | 340 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 340 KB | Output is correct |
14 | Correct | 0 ms | 340 KB | Output is correct |
15 | Incorrect | 0 ms | 340 KB | Output isn't correct |
16 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 340 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 340 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 0 ms | 340 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 340 KB | Output is correct |
14 | Correct | 0 ms | 340 KB | Output is correct |
15 | Incorrect | 0 ms | 340 KB | Output isn't correct |
16 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 340 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 340 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 0 ms | 340 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 340 KB | Output is correct |
14 | Correct | 0 ms | 340 KB | Output is correct |
15 | Incorrect | 0 ms | 340 KB | Output isn't correct |
16 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 340 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 340 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 0 ms | 340 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 340 KB | Output is correct |
14 | Correct | 0 ms | 340 KB | Output is correct |
15 | Incorrect | 0 ms | 340 KB | Output isn't correct |
16 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 340 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 340 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 0 ms | 340 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 340 KB | Output is correct |
14 | Correct | 0 ms | 340 KB | Output is correct |
15 | Incorrect | 0 ms | 340 KB | Output isn't correct |
16 | Halted | 0 ms | 0 KB | - |