1 #include <bits/stdc++.h>
 2 #define dbg(x) cout << #x << "=" << x << endl
 3 
 4 using namespace std;
 5 typedef long long LL;
 6 const int maxn = 3e5 + 7;
 7 
 8 LL f[maxn];
 9 char ch[maxn];
10 
11 namespace _buff {
12     const size_t BUFF = 1 << 19;
13     char ibuf[BUFF], *ib = ibuf, *ie = ibuf;
14     char getc() {
15         if (ib == ie) {
16             ib = ibuf;
17             ie = ibuf + fread(ibuf, 1, BUFF, stdin);
18         }
19         return ib == ie ? -1 : *ib++;
20     }
21 }
22 
23 int read() {
24     using namespace _buff;
25     int ret = 0;
26     bool pos = true;
27     char c = getc();
28     for (; (c < '0' || c > '9') && c != '-'; c = getc()) {
29         assert(~c);
30     }
31     if (c == '-') {
32         pos = false;
33         c = getc();
34     }
35     for (; c >= '0' && c <= '9'; c = getc()) {
36         ret = (ret << 3) + (ret << 1) + (c ^ 48);
37     }
38     return pos ? ret : -ret;
39 }
40 
41 int main()
42 {
43     int n,a,b,c;
44     scanf("%d %d %d %d\n",&n,&a,&b,&c);
45     scanf("%s",ch+1);
46     for(int i = 0; i <= n; ++i) {
47         if(i > 0) f[i] = f[i-1];
48         if(i >= 4 && ch[i-3] == 'n' && ch[i-2] == 'i' && ch[i-1] == 'c' && ch[i] == 'o') {
49             f[i] = max(f[i], f[i-3] + a);
50         }
51         if(i >= 6 && ch[i-5] == 'n' && ch[i-4] == 'i' && ch[i-3] == 'c' && ch[i-2] == 'o' && ch[i-1] == 'n' && ch[i] == 'i') {
52             f[i] = max(f[i], f[i-5] + b);
53         }
54         if(i >= 10 && ch[i-9] == 'n' && ch[i-8] == 'i' && ch[i-7] == 'c' && ch[i-6] == 'o' && ch[i-5] == 'n' && ch[i-4] == 'i' && ch[i-3] == 'c' && ch[i-2] == 'o' && ch[i-1] == 'n' && ch[i] == 'i') {
55             f[i] = max(f[i], f[i-9] + c);
56         }
57     }
58     cout << f[n] << endl;
59     return 0;
60 }
View Code