Submission #834712

#TimeUsernameProblemLanguageResultExecution timeMemory
834712AntekbChorus (JOI23_chorus)C++17
0 / 100
1 ms340 KiB
#include<bits/stdc++.h> #define st first #define nd second #define all(x) (x).begin(), (x).end() #define pb push_back #define eb emplace_back #define pp pop_back #define mp make_pair using namespace std; using pii = pair<int, int>; using ll = long long; using vi = vector<int>; using vii = vector<pii>; using ld = long double; void debug(){cerr<<"\n";} template<typename H, typename... T> void debug(H h, T... t){ cerr<<h; if(sizeof...(t)){ cerr<<", "; } debug(t...); } #define deb(x...) cerr<<#x<<" = ";debug(x); mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); int main(){ int n, k; string s; cin>>n>>k>>s; vi V(n+1); int a=0, b=1; for(char c:s){ if(c=='A'){ a++; } else{ V[b]=a; b++; } } /*vector<vector<ll> > dp(n+1, vector<ll>(k+1, 1e18)); dp[0][0]=0; for(int kk=1; kk<=k; kk++){ for(int i=kk; i<=n; i++){ ll c=0; for(int j=i-1; j>=0; j--){ c+=max(0, i-V[j+1]); dp[i][kk]=min(dp[i][kk], dp[j][kk-1]+c); } } }*/ vector<ld> dp(n+1), ile(n+1); ld l=-1e12, r=1e12; for(int ii=0; ii<100; ii++){ ld m=(l+r)/2; dp[0]=0; ile[0]=0; for(int i=1; i<=n; i++){ ll c=0; dp[i]=1e18; for(int j=i-1; j>=0; j--){ c+=max(0, i-V[j+1]); if(dp[i]>dp[j]+c+m){ dp[i]=dp[j]+c+m; ile[i]=ile[j]+1; } } } if(ile[n]>k)l=m; else if(ile[n]<k)r=m; else{ cout<<ll(dp[n]-k*m+0.5); return 0; } } assert(false); }
#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...