이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int N;
string S;
int f(char x) {
if(x == 'J') return 0;
if(x == 'O') return 1;
if(x == 'I') return 2;
}
struct node {
int a, b, c;
bool operator <(const node &i) const {
if(a != i.a) return a < i.a;
if(b != i.b) return b < i.b;
if(c != i.c) return c < i.c;
return false;
}
};
int cnt[3];
map<node, int> chk;
int main() {
cin >> N >> S;
int ans = 0;
chk[ {0, 0, 0} ] = -1;
for(int i = 0; i < N; i++) {
cnt[ f(S[i]) ]++;
int mn = min(cnt[0], min(cnt[1], cnt[2]));
if(chk.find({ cnt[0] - mn, cnt[1] - mn, cnt[2] - mn }) != chk.end()) {
ans = max(ans, i - chk[ { cnt[0] - mn, cnt[1] - mn, cnt[2] - mn } ]);
}
else chk[ { cnt[0] - mn, cnt[1] - mn, cnt[2] - mn } ] = i;
}
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
joioji.cpp: In function 'int f(char)':
joioji.cpp:11:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |