이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, k;
string s;
cin >> n >> k >> s;
string target = string(k, 'J') + string(k, 'O') + string(k, 'I');
ll ptr = 0;
ll mn = LLONG_MAX, mx = LLONG_MIN;
for (ll i = 0; i < n && ptr < target.length(); ++i) {
if (s[i] == target[ptr]) {
mn = min(mn, i);
mx = max(mx, i);
ptr++;
}
}
if (ptr != target.length()) {
cout << "-1\n";
return 0;
}
ptr--;
for (ll i = mx; i >= 0 && ptr >= 0; --i) {
if (s[i] == target[ptr]) {
mn = min(mn, i);
mx = max(mx, i);
ptr--;
}
}
cout << mx - mn + 1 - 3 * k << "\n";
}
컴파일 시 표준 에러 (stderr) 메시지
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:18:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for (ll i = 0; i < n && ptr < target.length(); ++i) {
| ~~~~^~~~~~~~~~~~~~~~~
ho_t2.cpp:26:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | if (ptr != target.length()) {
| ~~~~^~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |