#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define Unique(v) sort(all(v));v.erase(unique(all(v)),v.end());
#define sz(v) ((int)v.size())
using namespace std;
typedef vector<int> vi;
#define y1 abacaba
//#define left oooooopss
#define db(x) cerr << #x <<" == "<<x << endl;
#define db2(x,y) cerr<<#x <<" == "<<x<<", "<<#y<<" == "<<y<<endl;
#define db3(x,y,z) cerr << #x<<" == "<<x<<", "<<#y<<" == "<<y<<", "<<#z<<" == "<<z<<endl;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down
inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll b,ll e,ll m){
b%=m;
ll ans = 1;
for (; e; b = b * b % m, e /= 2)
if (e & 1) ans = ans * b % m;
return ans;
}
// debug:
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){
cerr << ' ' << H;
dbg_out(T...);
}
#ifdef LOCAL
#define dbg(...) cerr<<"(" << #__VA_ARGS__<<"):" , dbg_out(__VA_ARGS__) , cerr << endl
#else
#define dbg(...)
#endif
//
const int N = 70100;
int pre[N][20];
int nxt[N][20];
int32_t main(){
fastio;
int n;
cin >> n;
string s;
cin >> s;
rep(i,0,n){
rep(j,0,20){
pre[i][j] = (!i ? 0 : pre[i-1][j]);
}
pre[i][s[i]-'a']++;
}
per(i,0,n){
rep(j,0,20){
nxt[i][j] = (i==n-1 ? n : nxt[i+1][j]);
}
nxt[i][s[i]-'a'] = i;
}
ll res=0;
int cur = 0;
int tote=pre[n-1][4],foie=0;
while(tote > foie){
int prx = cur;
while(prx < n && s[prx]!='e')prx++;
int fim = prx;
while(fim +1 < n && s[fim + 1] == 'e')fim++;
int tam = fim - prx+1;
res += tam + tam;
foie += tam;
// custo de ir de cur pra fim + 1
int mn = 1e9;
for(int j=0;j<10;j++){
int pos = nxt[fim+1][j];
if(pos < n){
mn = min(mn,pre[pos][j] - pre[cur][j]);
}
}
res+=mn * 2;
cur = fim + 1;
}
cout<<res<<endl;
// math -> gcd it all
// Did u check N=1? Did you switch N,M?
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
9 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
10 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
11 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
13 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
15 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
16 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
17 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
18 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
19 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
20 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
21 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
22 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
23 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
24 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
25 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
26 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
27 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
28 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
29 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
30 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
31 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
32 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
33 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
34 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
35 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
36 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
1100 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
1100 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
716 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
1100 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
1100 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
1104 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
1100 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
1100 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
1100 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
1100 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
9932 KB |
Output isn't correct |
2 |
Incorrect |
8 ms |
9676 KB |
Output isn't correct |
3 |
Incorrect |
8 ms |
9932 KB |
Output isn't correct |
4 |
Incorrect |
9 ms |
11468 KB |
Output isn't correct |
5 |
Incorrect |
8 ms |
11468 KB |
Output isn't correct |
6 |
Incorrect |
10 ms |
10060 KB |
Output isn't correct |
7 |
Incorrect |
10 ms |
10452 KB |
Output isn't correct |
8 |
Incorrect |
10 ms |
10652 KB |
Output isn't correct |
9 |
Incorrect |
8 ms |
10608 KB |
Output isn't correct |
10 |
Incorrect |
8 ms |
10640 KB |
Output isn't correct |
11 |
Incorrect |
8 ms |
11468 KB |
Output isn't correct |
12 |
Incorrect |
8 ms |
11468 KB |
Output isn't correct |
13 |
Incorrect |
9 ms |
11084 KB |
Output isn't correct |
14 |
Incorrect |
8 ms |
11340 KB |
Output isn't correct |
15 |
Incorrect |
9 ms |
11340 KB |
Output isn't correct |
16 |
Incorrect |
8 ms |
9812 KB |
Output isn't correct |
17 |
Incorrect |
9 ms |
9932 KB |
Output isn't correct |
18 |
Incorrect |
9 ms |
9932 KB |
Output isn't correct |
19 |
Incorrect |
7 ms |
9676 KB |
Output isn't correct |
20 |
Incorrect |
7 ms |
9804 KB |
Output isn't correct |