제출 #1180038

#제출 시각아이디문제언어결과실행 시간메모리
1180038stefdascaJJOOII 2 (JOI20_ho_t2)C++20
1 / 100
0 ms328 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int n, k; cin >> n >> k; vector<char> joi(n); vector<char> j, o, i; for(int x = 0; x < n; x++) { cin >> joi[x]; if(joi[x] == 'J') { j.push_back(x); } else if(joi[x] == 'O') { o.push_back(x); } else { i.push_back(x); } } int ans = INT_MAX; for(int x = 0; x < j.size() - k + 1; x++) { int posO = lower_bound(o.begin(), o.end(), j[x + k - 1]) - o.begin(); if(posO < o.size() - k + 1) { int posI = lower_bound(i.begin(), i.end(), o[posO + k - 1]) - i.begin(); if(posI < i.size() - k + 1) { int cur = i[posI + k - 1]; ans = min(ans, (cur - j[x] - 3 * k + 1)); } } } if(ans == INT_MAX) { cout << -1 << endl; } else { cout << ans << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...