# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
581604 | Metal_Sonic | JJOOII 2 (JOI20_ho_t2) | C++17 | 2081 ms | 1116 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define sz(x) (int)(x).size()
#define all(x) x.begin() , x.end()
void setIO(string name = "") {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
if(sz(name)){
freopen((name+".in").c_str(), "r", stdin);
freopen((name+".out").c_str(), "w", stdout);
}
}
int n,k;
string s;
int solve(int j){
int cntj = 0, cnto = 0, cnti = 0;
int garbage = 0;
while(cntj != k && j < n){
if(s[j] == 'J')cntj++;
else garbage++;
j++;
}
while(cnto != k && j < n){
if(s[j] == 'O')cnto++;
else garbage++;
j++;
}
while(cnti != k && j < n){
if(s[j] == 'I')cnti++;
else garbage++;
j++;
}
if(cntj == k && cnto == k && cnti == k)return garbage;
return 5000;
}
void run_test_case(){
cin>>n>>k>>s;
vector<int>J;
for(int i = 0; i < n; i++){
if(s[i]=='J')J.push_back(i);
}
int ans = 5000;
for(auto it : J){
ans = min(ans,solve(it));
}
cout<<(ans == 5000 ? -1 : ans);
}
int main() {
setIO();
int T = 1;
while(T--){
run_test_case();
}
return 0;
}
컴파일 시 표준 에러 (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... |