// Author: kyEEcccccc
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define F(i, l, r) for (int i = (l); i <= (r); ++i)
#define FF(i, r, l) for (int i = (r); i >= (l); --i)
#define MAX(a, b) ((a) = max(a, b))
#define MIN(a, b) ((a) = min(a, b))
const int N = 70005;
int f[N][10], g[N][10][10], h[N][10];
void trans_f(int to, int c, int x, int val, int aaa)
{
if (x == c)
{
F(xx, 0, 9)
{
if (xx == 4)
{
continue;
}
MIN(f[to][xx], val + 2);
MIN(h[to][xx], val + 3);
F(yy, 0, 9)
{
if (yy == 4)
{
continue;
}
MIN(g[to][xx][yy], val + 3);
}
}
}
else
{
if (!aaa)
{
MIN(f[to][x], val);
}
MIN(h[to][x], val + 1);
F(yy, 0, 9)
{
if (yy == 4)
{
continue;
}
MIN(g[to][x][yy], val + 1);
}
}
}
void trans_h(int to, int c, int x, int val)
{
if (c == x)
{
F(xx, 0, 9)
{
if (xx == 4)
{
continue;
}
MIN(h[to][xx], val + 3);
}
}
else
{
MIN(h[to][x], val + 1);
}
}
void trans_g(int to, int c, int x, int y, int val)
{
if (c == x && c == y)
{
F(xx, 0, 9)
{
if (xx == 4)
{
continue;
}
MIN(f[to][xx], val + 4);
MIN(h[to][xx], val + 5);
F(yy, 0, 9)
{
if (yy == 4)
{
continue;
}
MIN(g[to][xx][yy], val + 5);
}
}
}
else if (c != x && c != y)
{
MIN(g[to][x][y], val + 1);
}
else
{
MIN(f[to][c ^ x ^ y], val + 2);
MIN(h[to][c ^ x ^ y], val + 3);
F(xx, 0, 9)
{
if (xx == 4)
{
continue;
}
if (x == c)
{
MIN(g[to][xx][y], val + 3);
}
else
{
MIN(g[to][x][xx], val + 3);
}
}
}
}
int aa[N];
int main(void)
{
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
ios::sync_with_stdio(0), cin.tie(nullptr);
int n;
string s, t;
cin >> n >> t;
int is = 0, x = 0;
F(i, 0, n-1)
{
if (t[i] == 'e')
{
is = 1;
x += 2;
}
else
{
aa[s.size()] = is;
is = 0;
s += t[i];
}
}
n = s.size();
F(i, 0, n-1) F(x, 0, 9) F(y, 0, 9)
{
h[i][x] = f[i][x] = g[i][x][y] = INT_MAX / 4;
}
F(i, 0, 9)
{
if (i != 4)
{
f[0][i] = 0;
}
}
F(i, 0, n-2) F(x, 0, 9)
{
if (x == 4)
{
continue;
}
trans_f(i+1, s[i+1] - 'a', x, f[i][x], aa[i]);
trans_h(i+1, s[i+1] - 'a', x, h[i][x]);
F(y, 0, 9)
{
if (y == 4)
{
continue;
}
trans_g(i+1, s[i+1] - 'a', x, y, g[i][x][y]);
}
}
int ans = INT_MAX / 4;
FF(i, n-1, 1)
{
ans = min(ans, h[i-1][s[i] - 'a']);
if (aa[i])
{
break;
}
}
ans += x;
cout << ans + 2 << '\n';
return 0;
}
交上去就是Judging很久返回编译失败。复制了题解交上去就能测,不知道为啥,我这代码里有什么不能编译或者不能交的东西吗?还是因为宏定义?换过语言,不开O2也试过了,就是不行。把这道题的代码交到别的题目上去立刻评测出RE,为啥交这里连编译都不行?