답안 #51152

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
51152 2018-06-17T01:51:50 Z 노영훈(#1283, Diuven) 스탬프 수집 (JOI16_ho_t2) C++11
100 / 100
6 ms 1528 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 480 KB Output is correct
3 Correct 3 ms 480 KB Output is correct
4 Correct 2 ms 480 KB Output is correct
5 Correct 2 ms 544 KB Output is correct
6 Correct 2 ms 560 KB Output is correct
7 Correct 2 ms 660 KB Output is correct
8 Correct 2 ms 660 KB Output is correct
9 Correct 2 ms 660 KB Output is correct
10 Correct 2 ms 660 KB Output is correct
11 Correct 2 ms 660 KB Output is correct
12 Correct 2 ms 744 KB Output is correct
13 Correct 2 ms 744 KB Output is correct
14 Correct 2 ms 744 KB Output is correct
15 Correct 2 ms 744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 480 KB Output is correct
3 Correct 3 ms 480 KB Output is correct
4 Correct 2 ms 480 KB Output is correct
5 Correct 2 ms 544 KB Output is correct
6 Correct 2 ms 560 KB Output is correct
7 Correct 2 ms 660 KB Output is correct
8 Correct 2 ms 660 KB Output is correct
9 Correct 2 ms 660 KB Output is correct
10 Correct 2 ms 660 KB Output is correct
11 Correct 2 ms 660 KB Output is correct
12 Correct 2 ms 744 KB Output is correct
13 Correct 2 ms 744 KB Output is correct
14 Correct 2 ms 744 KB Output is correct
15 Correct 2 ms 744 KB Output is correct
16 Correct 2 ms 744 KB Output is correct
17 Correct 2 ms 744 KB Output is correct
18 Correct 2 ms 744 KB Output is correct
19 Correct 2 ms 744 KB Output is correct
20 Correct 2 ms 744 KB Output is correct
21 Correct 2 ms 744 KB Output is correct
22 Correct 3 ms 760 KB Output is correct
23 Correct 2 ms 760 KB Output is correct
24 Correct 2 ms 760 KB Output is correct
25 Correct 2 ms 760 KB Output is correct
26 Correct 2 ms 760 KB Output is correct
27 Correct 2 ms 760 KB Output is correct
28 Correct 2 ms 760 KB Output is correct
29 Correct 2 ms 760 KB Output is correct
30 Correct 2 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 480 KB Output is correct
3 Correct 3 ms 480 KB Output is correct
4 Correct 2 ms 480 KB Output is correct
5 Correct 2 ms 544 KB Output is correct
6 Correct 2 ms 560 KB Output is correct
7 Correct 2 ms 660 KB Output is correct
8 Correct 2 ms 660 KB Output is correct
9 Correct 2 ms 660 KB Output is correct
10 Correct 2 ms 660 KB Output is correct
11 Correct 2 ms 660 KB Output is correct
12 Correct 2 ms 744 KB Output is correct
13 Correct 2 ms 744 KB Output is correct
14 Correct 2 ms 744 KB Output is correct
15 Correct 2 ms 744 KB Output is correct
16 Correct 2 ms 744 KB Output is correct
17 Correct 2 ms 744 KB Output is correct
18 Correct 2 ms 744 KB Output is correct
19 Correct 2 ms 744 KB Output is correct
20 Correct 2 ms 744 KB Output is correct
21 Correct 2 ms 744 KB Output is correct
22 Correct 3 ms 760 KB Output is correct
23 Correct 2 ms 760 KB Output is correct
24 Correct 2 ms 760 KB Output is correct
25 Correct 2 ms 760 KB Output is correct
26 Correct 2 ms 760 KB Output is correct
27 Correct 2 ms 760 KB Output is correct
28 Correct 2 ms 760 KB Output is correct
29 Correct 2 ms 760 KB Output is correct
30 Correct 2 ms 760 KB Output is correct
31 Correct 3 ms 1404 KB Output is correct
32 Correct 4 ms 1404 KB Output is correct
33 Correct 3 ms 1404 KB Output is correct
34 Correct 4 ms 1404 KB Output is correct
35 Correct 4 ms 1404 KB Output is correct
36 Correct 5 ms 1408 KB Output is correct
37 Correct 5 ms 1408 KB Output is correct
38 Correct 5 ms 1408 KB Output is correct
39 Correct 5 ms 1408 KB Output is correct
40 Correct 5 ms 1408 KB Output is correct
41 Correct 6 ms 1408 KB Output is correct
42 Correct 6 ms 1528 KB Output is correct
43 Correct 5 ms 1528 KB Output is correct
44 Correct 6 ms 1528 KB Output is correct
45 Correct 3 ms 1528 KB Output is correct