Submission #491175

#TimeUsernameProblemLanguageResultExecution timeMemory
491175AdamGSVim (BOI13_vim)C++14
42.50 / 100
227 ms9204 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() const int LIM=7e4+7, INF=1e9+7; int nxt[LIM][10], odl[LIM][10], kiedy[10]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; string s; cin >> n >> s; rep(i, n) { if(s[i]=='e') s[i]='a'; else if(s[i]=='a') s[i]='e'; } rep(i, 10) kiedy[i]=INF; for(int i=n-1; i>=0; --i) { rep(j, 10) { nxt[i][j]=kiedy[j]; odl[i][j]=INF; } kiedy[s[i]-'a']=i; } priority_queue<pair<int,pair<int,int>>>q; q.push({0, {0, 0}}); while(!q.empty()) { int o=-q.top().st, a=q.top().nd.st, b=q.top().nd.nd; q.pop(); if(o>=odl[a][b]) continue; odl[a][b]=o; int p=nxt[a][b]; if(!b) p=a; if(nxt[p][0]==INF) { rep(i, n) if(s[i]=='a') ++o; cout << o << '\n'; break; } for(int i=1; i<10; ++i) if(nxt[a][i]<INF && nxt[a][i]>=p) { if(nxt[p][0]>nxt[a][i]) { if(odl[nxt[a][i]][i]==INF) q.push({-o-2, {nxt[a][i], 0}}); } else { int mi=INF, c=i; for(int j=1; j<10; ++j) mi=min(mi, nxt[nxt[p][0]][j]); if(nxt[a][i]==mi) c=0; if(odl[mi][c]==INF) q.push({-o-2-nxt[a][i]+nxt[p][0], {mi, c}}); } } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...