답안 #136943

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
136943 2019-07-26T15:53:07 Z arnold518 스탬프 수집 (JOI16_ho_t2) C++14
100 / 100
6 ms 2168 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5;

int N;
char S[MAXN+10];

ll pj[MAXN+10], pi[MAXN+10], ans;

int main()
{
    int i, j;

    scanf("%d%s", &N, S+1);
    for(i=1; i<=N; i++) pj[i]=pj[i-1]+(S[i]=='J');
    for(i=N; i>=1; i--) pi[i]=pi[i+1]+(S[i]=='I');

    ll now=0;
    for(i=1; i<N; i++) now=max(now, pj[i]*pi[i+1]);
    for(i=1; i<=N; i++) if(S[i]=='O') now+=pj[i]*pi[i];
    ans=max(ans, now);

    now=0;
    for(i=1; i<=N; i++) if(S[i]=='O') now+=(pj[i]+1)*pi[i];
    ans=max(ans, now);

    now=0;
    for(i=1; i<=N; i++) if(S[i]=='O') now+=pj[i]*(pi[i]+1);
    ans=max(ans, now);

    printf("%lld", ans);
}

Compilation message

2016_ho_t2.cpp: In function 'int main()':
2016_ho_t2.cpp:17:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
2016_ho_t2.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%s", &N, S+1);
     ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 4 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 4 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 5 ms 2040 KB Output is correct
32 Correct 5 ms 2040 KB Output is correct
33 Correct 5 ms 2040 KB Output is correct
34 Correct 5 ms 2168 KB Output is correct
35 Correct 5 ms 2040 KB Output is correct
36 Correct 6 ms 2040 KB Output is correct
37 Correct 6 ms 2040 KB Output is correct
38 Correct 6 ms 2044 KB Output is correct
39 Correct 6 ms 2040 KB Output is correct
40 Correct 6 ms 2040 KB Output is correct
41 Correct 6 ms 2040 KB Output is correct
42 Correct 6 ms 2040 KB Output is correct
43 Correct 6 ms 2040 KB Output is correct
44 Correct 6 ms 2040 KB Output is correct
45 Correct 6 ms 2040 KB Output is correct