# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|
378395 | | YJU | Vim (BOI13_vim) | C++14 | | 431 ms | 398444 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector,Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll N=5e3+5;
const ll INF=(1LL<<60);
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define lwb lower_bound
ll nxt[N][20],suffix_sum[N],dp[N][N];
string s;
vector<ll> loc;
ll n,m;
ll f(ll have,ll id){
if(have==m)return 0;
if(dp[have][id]!=-1)return dp[have][id];
//cout<<have<<" "<<id<<"\n";
dp[have][id]=INF;
REP(j,11){
if(j=='e'-'a'||nxt[id+1][j]==n)continue;
ll to=nxt[id+1][j];
if(to>loc[have]){
ll nhave=lwb(loc.begin(),loc.end(),to)-loc.begin();
dp[have][id]=min(dp[have][id],2+(to-loc[have])+f(nhave,loc[have]+1));
}else{
dp[have][id]=min(dp[have][id],f(have,to)+2);
}
}
return dp[have][id];
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
memset(dp,-1,sizeof(dp));
cin>>n>>s;
REP(j,11)nxt[n][j]=n;
for(int i=n-1;i>=0;i--){
REP(j,11)nxt[i][j]=nxt[i+1][j];
nxt[i][s[i]-'a']=i;
if(s[i]=='e')loc.pb(i);
}
sort(loc.begin(),loc.end());
m=loc.size();
cout<<f(0,0)+m<<"\n";
//REP(i,m)REP(j,n)cout<<i<<" "<<j<<" "<<dp[i][j]<<"\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |