Submission #70466

# Submission time Handle Problem Language Result Execution time Memory
70466 2018-08-23T02:23:43 Z Diuven None (JOI16_ho_t2) C++14
100 / 100
6 ms 3244 KB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int MX=100010, inf=2e9;

int n;
char S[MX];

int Jcnt[MX], Icnt[MX];
ll base;

ll J(){
  ll res=base;
  for(int i=1; i<=n; i++)
    if(S[i]=='O') res+=Icnt[i];
  return res;
}

ll I(){
  ll res=base;
  for(int i=n; i>=1; i--)
    if(S[i]=='O') res+=Jcnt[i];
  return res;
}

ll O(){
  ll mx=0;
  for(int i=1; i<=n; i++){
    mx=max(mx, 1LL*Jcnt[i-1]*Icnt[i]);
  }
  return base+mx;
}

int main(){
  ios::sync_with_stdio(0); cin.tie(0);
  cin>>n>>(S+1);
  for(int i=1; i<=n; i++)
    Jcnt[i]=Jcnt[i-1]+(S[i]=='J');
  for(int i=n; i>=1; i--)
    Icnt[i]=Icnt[i+1]+(S[i]=='I');
  for(int i=1; i<=n; i++)
    if(S[i]=='O') base+=1LL*Jcnt[i]*Icnt[i];
  ll ans=max({J(), I(), O()});
  cout<<ans;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 3 ms 488 KB Output is correct
4 Correct 4 ms 640 KB Output is correct
5 Correct 3 ms 752 KB Output is correct
6 Correct 2 ms 752 KB Output is correct
7 Correct 3 ms 868 KB Output is correct
8 Correct 3 ms 868 KB Output is correct
9 Correct 2 ms 868 KB Output is correct
10 Correct 2 ms 868 KB Output is correct
11 Correct 2 ms 884 KB Output is correct
12 Correct 2 ms 884 KB Output is correct
13 Correct 3 ms 884 KB Output is correct
14 Correct 3 ms 884 KB Output is correct
15 Correct 2 ms 884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 3 ms 488 KB Output is correct
4 Correct 4 ms 640 KB Output is correct
5 Correct 3 ms 752 KB Output is correct
6 Correct 2 ms 752 KB Output is correct
7 Correct 3 ms 868 KB Output is correct
8 Correct 3 ms 868 KB Output is correct
9 Correct 2 ms 868 KB Output is correct
10 Correct 2 ms 868 KB Output is correct
11 Correct 2 ms 884 KB Output is correct
12 Correct 2 ms 884 KB Output is correct
13 Correct 3 ms 884 KB Output is correct
14 Correct 3 ms 884 KB Output is correct
15 Correct 2 ms 884 KB Output is correct
16 Correct 2 ms 884 KB Output is correct
17 Correct 3 ms 884 KB Output is correct
18 Correct 3 ms 884 KB Output is correct
19 Correct 3 ms 884 KB Output is correct
20 Correct 2 ms 884 KB Output is correct
21 Correct 2 ms 884 KB Output is correct
22 Correct 3 ms 884 KB Output is correct
23 Correct 3 ms 884 KB Output is correct
24 Correct 3 ms 884 KB Output is correct
25 Correct 2 ms 884 KB Output is correct
26 Correct 2 ms 892 KB Output is correct
27 Correct 3 ms 892 KB Output is correct
28 Correct 2 ms 892 KB Output is correct
29 Correct 2 ms 892 KB Output is correct
30 Correct 2 ms 892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 3 ms 488 KB Output is correct
4 Correct 4 ms 640 KB Output is correct
5 Correct 3 ms 752 KB Output is correct
6 Correct 2 ms 752 KB Output is correct
7 Correct 3 ms 868 KB Output is correct
8 Correct 3 ms 868 KB Output is correct
9 Correct 2 ms 868 KB Output is correct
10 Correct 2 ms 868 KB Output is correct
11 Correct 2 ms 884 KB Output is correct
12 Correct 2 ms 884 KB Output is correct
13 Correct 3 ms 884 KB Output is correct
14 Correct 3 ms 884 KB Output is correct
15 Correct 2 ms 884 KB Output is correct
16 Correct 2 ms 884 KB Output is correct
17 Correct 3 ms 884 KB Output is correct
18 Correct 3 ms 884 KB Output is correct
19 Correct 3 ms 884 KB Output is correct
20 Correct 2 ms 884 KB Output is correct
21 Correct 2 ms 884 KB Output is correct
22 Correct 3 ms 884 KB Output is correct
23 Correct 3 ms 884 KB Output is correct
24 Correct 3 ms 884 KB Output is correct
25 Correct 2 ms 884 KB Output is correct
26 Correct 2 ms 892 KB Output is correct
27 Correct 3 ms 892 KB Output is correct
28 Correct 2 ms 892 KB Output is correct
29 Correct 2 ms 892 KB Output is correct
30 Correct 2 ms 892 KB Output is correct
31 Correct 4 ms 1732 KB Output is correct
32 Correct 5 ms 1868 KB Output is correct
33 Correct 5 ms 1948 KB Output is correct
34 Correct 5 ms 2064 KB Output is correct
35 Correct 5 ms 2164 KB Output is correct
36 Correct 6 ms 2392 KB Output is correct
37 Correct 5 ms 2392 KB Output is correct
38 Correct 5 ms 2480 KB Output is correct
39 Correct 6 ms 2584 KB Output is correct
40 Correct 5 ms 2704 KB Output is correct
41 Correct 5 ms 2800 KB Output is correct
42 Correct 5 ms 2904 KB Output is correct
43 Correct 5 ms 3000 KB Output is correct
44 Correct 6 ms 3228 KB Output is correct
45 Correct 5 ms 3244 KB Output is correct