제출 #1316852

#제출 시각아이디문제언어결과실행 시간메모리
1316852pobeJJOOII 2 (JOI20_ho_t2)C++20
100 / 100
30 ms3004 KiB
#include <bits/stdc++.h> #define int long long using namespace std; ostream &operator <<(ostream &out, vector <int> val) { for (auto v : val) { out << v << ' '; } return out; } void solve() { int n, k; cin >> n >> k; string s; vector <vector <int>> ind(3); cin >> s; for (int i = 0; i < n; ++i) { if (s[i] == 'J') { ind[0].push_back(i); } else if (s[i] == 'O') { ind[1].push_back(i); } else { ind[2].push_back(i); } } int ans = 2e9; for (int i = 0; i < n; ++i) { int num = i; bool flag = true; for (int j = 0; j < 3; ++j) { if (ind[j].empty()) { flag = false; } else { int res = lower_bound(ind[j].begin(), ind[j].end(), num) - ind[j].begin(); res += k - 1; if (res < ind[j].size()) { num = ind[j][res] + 1; } else { flag = false; } } } if (flag) { ans = min(ans, num - i - 3 * k); } } if (ans == 2e9) { cout << - 1 << '\n'; } else { cout << ans << '\n'; } } signed main() { cin.tie(0); ios::sync_with_stdio(false); int t = 1; solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...