# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
58744 | leejseo | 스탬프 수집 (JOI16_ho_t2) | C++98 | 13 ms | 6800 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long lld;
const int MAXN = 100000;
int N, L[MAXN+1][3], R[MAXN+1][3], A[MAXN];
lld X[MAXN+1], Y[MAXN+1];
char s[MAXN+1];
lld S;
inline int conv(char c){
if (c == 'J') return 0;
if (c == 'O') return 1;
return 2;
}
void input(){
scanf("%d\n", &N);
scanf("%s", s);
for (int i=0; i<N; i++) A[i] = conv(s[i]);
}
void init(){
for (int i=0; i<N; i++){
L[i+1][0] = L[i][0];
L[i+1][1] = L[i][1];
L[i+1][2] = L[i][2];
L[i+1][A[i]]++;
}
for (int i=N-1; i>=0; i--){
R[i][0] = R[i+1][0];
R[i][1] = R[i+1][1];
R[i][2] = R[i+1][2];
R[i][A[i]]++;
}
for (int i=0; i<N; i++){
if (A[i] == 1){
X[i] = L[i][0];
Y[i] = R[i][2];
S += L[i][0] * (lld) R[i][2];
}
}
for (int i=1; i<=N; i++) X[i] += X[i-1];
for (int i=N-1; i>=0; i--) Y[i] += Y[i+1];
}
lld solve(){
lld ans = 0;
for (int i=0; i<=N; i++){
ans = max(ans, Y[i]);
ans = max(ans, X[i]);
ans = max(ans, L[i][0] * (lld)R[i][2]);
}
return ans;
}
int main(){
input();
init();
printf("%lld\n", S+solve());
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |