#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
int cnt[3];
int ans;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int N,K; cin >> N >> K;
int first = 0; int last = N - 1;
string s; cin >> s;
for(int i = 0; i < N; i++) {
if(cnt[0] != K) {
if(s[i] == 'J') cnt[0]++;
else{
if(i == first) first++;
else if(i == last) last--;
else ans++;
}
}
else if(cnt[1] != K) {
if(s[i] == 'O') cnt[1]++;
else{
if(i == first) first++;
else if(i == last) last--;
else ans++;
}
}
else if(cnt[2] != K) {
if(s[i] == 'I') cnt[2]++;
else{
if(i == first) first++;
else if(i == last) last--;
else ans++;
}
}
}
for(int i = 0; i < 3; i++) {
if(cnt[i] != K) {
cout << -1;
return 0;
}
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |