Submission #161906

# Submission time Handle Problem Language Result Execution time Memory
161906 2019-11-05T09:23:47 Z impri None (JOI16_ho_t2) C++14
100 / 100
17 ms 7716 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
string s;
ll dp[100001][3];
char joi[4];
ll get(int a,int b){
if(b==0)return 1;
if(a>=n)return 0;
if(dp[a][b]>=0)return dp[a][b];
if(joi[b]==s[a])return dp[a][b]=get(a+1,b)+get(a+1,b-1);
return dp[a][b]=get(a+1,b);

}
int main()
{  cout <<fixed;cout.precision(12);cin.tie(0);
   ios_base::sync_with_stdio(false);
   memset(dp,-1,sizeof(dp));
   cin >> n;
   cin >> s;
   joi[1]='I';
   joi[2]='O';
   joi[3]='J';
   ll res=get(0,3);
   ll add=get(0,2);
   joi[2]='J';
   joi[1]='O';
   memset(dp,-1,sizeof(dp));
   add=max(add,get(0,2));
   int jnum=0;
   int inum=0;
   for(int i=0;i<n;i++)
    if(s[i]=='I')inum++;
   for(int i=0;i<n;i++){
     if(s[i]=='J')jnum++;
     if(s[i]=='I')inum--;
     add=max(add,1LL*jnum*inum);
   }
   cout << res+add;
}


# Verdict Execution time Memory Grader output
1 Correct 4 ms 2620 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2680 KB Output is correct
4 Correct 4 ms 2764 KB Output is correct
5 Correct 4 ms 2680 KB Output is correct
6 Correct 4 ms 2680 KB Output is correct
7 Correct 4 ms 2680 KB Output is correct
8 Correct 4 ms 2680 KB Output is correct
9 Correct 4 ms 2680 KB Output is correct
10 Correct 4 ms 2760 KB Output is correct
11 Correct 4 ms 2680 KB Output is correct
12 Correct 4 ms 2680 KB Output is correct
13 Correct 4 ms 2768 KB Output is correct
14 Correct 4 ms 2680 KB Output is correct
15 Correct 4 ms 2680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2620 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2680 KB Output is correct
4 Correct 4 ms 2764 KB Output is correct
5 Correct 4 ms 2680 KB Output is correct
6 Correct 4 ms 2680 KB Output is correct
7 Correct 4 ms 2680 KB Output is correct
8 Correct 4 ms 2680 KB Output is correct
9 Correct 4 ms 2680 KB Output is correct
10 Correct 4 ms 2760 KB Output is correct
11 Correct 4 ms 2680 KB Output is correct
12 Correct 4 ms 2680 KB Output is correct
13 Correct 4 ms 2768 KB Output is correct
14 Correct 4 ms 2680 KB Output is correct
15 Correct 4 ms 2680 KB Output is correct
16 Correct 6 ms 2808 KB Output is correct
17 Correct 6 ms 2808 KB Output is correct
18 Correct 4 ms 2808 KB Output is correct
19 Correct 5 ms 2808 KB Output is correct
20 Correct 4 ms 2808 KB Output is correct
21 Correct 4 ms 2880 KB Output is correct
22 Correct 4 ms 2780 KB Output is correct
23 Correct 4 ms 2856 KB Output is correct
24 Correct 4 ms 2808 KB Output is correct
25 Correct 5 ms 2940 KB Output is correct
26 Correct 4 ms 2808 KB Output is correct
27 Correct 4 ms 2808 KB Output is correct
28 Correct 4 ms 2812 KB Output is correct
29 Correct 4 ms 2780 KB Output is correct
30 Correct 5 ms 2780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2620 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2680 KB Output is correct
4 Correct 4 ms 2764 KB Output is correct
5 Correct 4 ms 2680 KB Output is correct
6 Correct 4 ms 2680 KB Output is correct
7 Correct 4 ms 2680 KB Output is correct
8 Correct 4 ms 2680 KB Output is correct
9 Correct 4 ms 2680 KB Output is correct
10 Correct 4 ms 2760 KB Output is correct
11 Correct 4 ms 2680 KB Output is correct
12 Correct 4 ms 2680 KB Output is correct
13 Correct 4 ms 2768 KB Output is correct
14 Correct 4 ms 2680 KB Output is correct
15 Correct 4 ms 2680 KB Output is correct
16 Correct 6 ms 2808 KB Output is correct
17 Correct 6 ms 2808 KB Output is correct
18 Correct 4 ms 2808 KB Output is correct
19 Correct 5 ms 2808 KB Output is correct
20 Correct 4 ms 2808 KB Output is correct
21 Correct 4 ms 2880 KB Output is correct
22 Correct 4 ms 2780 KB Output is correct
23 Correct 4 ms 2856 KB Output is correct
24 Correct 4 ms 2808 KB Output is correct
25 Correct 5 ms 2940 KB Output is correct
26 Correct 4 ms 2808 KB Output is correct
27 Correct 4 ms 2808 KB Output is correct
28 Correct 4 ms 2812 KB Output is correct
29 Correct 4 ms 2780 KB Output is correct
30 Correct 5 ms 2780 KB Output is correct
31 Correct 15 ms 7672 KB Output is correct
32 Correct 13 ms 7668 KB Output is correct
33 Correct 14 ms 7716 KB Output is correct
34 Correct 14 ms 7648 KB Output is correct
35 Correct 13 ms 7672 KB Output is correct
36 Correct 16 ms 7672 KB Output is correct
37 Correct 16 ms 7636 KB Output is correct
38 Correct 16 ms 7672 KB Output is correct
39 Correct 16 ms 7672 KB Output is correct
40 Correct 17 ms 7672 KB Output is correct
41 Correct 16 ms 7644 KB Output is correct
42 Correct 15 ms 7672 KB Output is correct
43 Correct 15 ms 7672 KB Output is correct
44 Correct 15 ms 7672 KB Output is correct
45 Correct 13 ms 7676 KB Output is correct