/* -*- coding: utf-8 -*- * * 2076.cc: No.2076 Concon Substrings (ConVersion) - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_N = 50000; const int MAX_M = MAX_N / 3; const int MAX_K = MAX_N / 3; /* typedef */ /* global variables */ char s[MAX_N + 4]; int ls[MAX_M], dp[2][MAX_K + 1]; /* subroutines */ inline void setmax(int &a, int b) { if (a < b) a = b; } /* main */ int main() { int n, a, b; scanf("%d%d%d%s", &n, &a, &b, s); int k = n / 3; int m = 0; for (int i = 0; i + 2 < n;) { while (i + 2 < n && s[i] != 'c') i++; if (i + 2 >= n) break; int j = i; while (i + 2 < n && s[i] == 'c' && s[i + 1] == 'o' && s[i + 2] == 'n') i += 3; int a = (i - j) / 3; if (a > 0) ls[m++] = a; else i++; } //for (int i = 0; i < m; i++) printf(" %d", ls[i]); putchar('\n'); fill(dp[0], dp[0] + k + 1, -1); dp[0][0] = 0; int cur = 0, nxt = 1; for (int i = 0; i < k; i++) { fill(dp[nxt], dp[nxt] + k + 1, -1); for (int j = 0; j <= k; j++) if (dp[cur][j] >= 0) { for (int j1 = 0; j + j1 <= k && j1 * a <= ls[i]; j1++) setmax(dp[nxt][j + j1], dp[cur][j] + (ls[i] - j1 * a) / b); } swap(cur, nxt); } int maxc = 0; for (int j = 1; j <= k; j++) { if (dp[cur][j] >= j) setmax(maxc, j * 2); else if (dp[cur][j] >= j - 1) setmax(maxc, j * 2 - 1); } printf("%d\n", maxc); return 0; }