제출 #741489

#제출 시각아이디문제언어결과실행 시간메모리
741489arnold518Chorus (JOI23_chorus)C++17
16 / 100
2 ms340 KiB
#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}; for(int i=1; i<=N; i++) { dp[i]={9e18, 0}; for(int j=0; j<i; j++) { dp[i]=min(dp[i], {dp[j].first+lambda+2*f(j+1, i), dp[j].second+1}); } } 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=0, 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); }

컴파일 시 표준 에러 (stderr) 메시지

chorus.cpp: In function 'int main()':
chorus.cpp:69:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   69 |   ll mid=lo+hi>>1;
      |          ~~^~~
chorus.cpp:41:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |  scanf("%d%d", &N, &K);
      |  ~~~~~^~~~~~~~~~~~~~~~
chorus.cpp:42:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |  scanf(" %s", S+1);
      |  ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...