답안 #136950

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
136950 2019-07-26T16:20:51 Z ksmzzang2003 스탬프 수집 (JOI16_ho_t2) C++14
0 / 100
2 ms 380 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N;
string A;
ll pi[100003],pj[100003],po[100003],rpi[100003],rpo[100003],rpj[100003];
ll j,o,i,ret=-1;
int main() {
    cin>>N>>A;
    for(ll i=0; i<N; i++) {
        pj[i] = ((i>0)?pj[i-1]:0) +(A[i]=='J');
        po[i] = ((i>0)?po[i-1]:0) +(A[i]=='O');
        pi[i] = ((i>0)?pi[i-1]:0) +(A[i]=='I');
    }
    ll maxv = -1;
    for(ll i=N-1; i>=0; i--) {
        rpi[i] = rpi[i+1]+(A[i]=='I');
        rpj[i] = rpj[i+1]+(A[i]=='J');
        rpo[i] = rpo[i+1]+(A[i]=='O');
    }
    for(ll i=0;i<N;i++) if(A[i]=='O') o+=pj[i]*rpi[i],maxv=max(maxv,pj[i]*rpi[i]); o+=maxv; ret = max(ret,o);
    o=0;
    string B = A;
    A='J'+B; N++;
    for(ll i=0; i<N; i++) {
         pj[i] = ((i>0)?pj[i-1]:0)+(A[i]=='J');
        po[i] = ((i>0)?po[i-1]:0)+(A[i]=='O');
        pi[i] = ((i>0)?pi[i-1]:0)+(A[i]=='I');
    }
    for(ll i=N-1; i>=0; i--) {
        rpi[i] = rpi[i+1]+(A[i]=='I');
        rpj[i] = rpj[i+1]+(A[i]=='J');
        rpo[i] = rpo[i+1]+(A[i]=='O');
    }
    for(ll i=0;i<N;i++) if(A[i]=='O') o+=pj[i]*rpi[i];  ret = max(ret,o);
    o=0;
    A= B+'I';
    for(ll i=0; i<N; i++) {
         pj[i] = ((i>0)?pj[i-1]:0)+(A[i]=='J');
        po[i] = ((i>0)?po[i-1]:0)+(A[i]=='O');
        pi[i] = ((i>0)?pi[i-1]:0)+(A[i]=='I');
    }
    for(ll i=N-1; i>=0; i--) {
        rpi[i] = rpi[i+1]+(A[i]=='I');
        rpj[i] = rpj[i+1]+(A[i]=='J');
        rpo[i] = rpo[i+1]+(A[i]=='O');
    }
    for(ll i=0;i<N;i++) if(A[i]=='O') o+=pj[i]*rpi[i]; ret = max(ret,o);
    o=0;
    printf("%lld",ret);
}

Compilation message

2016_ho_t2.cpp: In function 'int main()':
2016_ho_t2.cpp:21:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for(ll i=0;i<N;i++) if(A[i]=='O') o+=pj[i]*rpi[i],maxv=max(maxv,pj[i]*rpi[i]); o+=maxv; ret = max(ret,o);
     ^~~
2016_ho_t2.cpp:21:84: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
     for(ll i=0;i<N;i++) if(A[i]=='O') o+=pj[i]*rpi[i],maxv=max(maxv,pj[i]*rpi[i]); o+=maxv; ret = max(ret,o);
                                                                                    ^
2016_ho_t2.cpp:35:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for(ll i=0;i<N;i++) if(A[i]=='O') o+=pj[i]*rpi[i];  ret = max(ret,o);
     ^~~
2016_ho_t2.cpp:35:57: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
     for(ll i=0;i<N;i++) if(A[i]=='O') o+=pj[i]*rpi[i];  ret = max(ret,o);
                                                         ^~~
2016_ho_t2.cpp:48:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for(ll i=0;i<N;i++) if(A[i]=='O') o+=pj[i]*rpi[i]; ret = max(ret,o);
     ^~~
2016_ho_t2.cpp:48:56: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
     for(ll i=0;i<N;i++) if(A[i]=='O') o+=pj[i]*rpi[i]; ret = max(ret,o);
                                                        ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 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 380 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 Incorrect 2 ms 376 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 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 380 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 Incorrect 2 ms 376 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 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 380 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 Incorrect 2 ms 376 KB Output isn't correct
14 Halted 0 ms 0 KB -