제출 #591459

#제출 시각아이디문제언어결과실행 시간메모리
591459piOOEJJOOII 2 (JOI20_ho_t2)C++17
0 / 100
0 ms212 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, k; cin >> n >> k; //j = 0, o = 1, i = 2 vector<int> g[3]; string s; cin >> s; int ans = n; for (int i = 0; i < n; ++i) { g[s[i] == 'J' ? 0 : s[i] == 'O' ? 1 : 2].push_back(i); } auto nxt = [&](int t, int i) { auto it = upper_bound(g[t].begin(), g[t].end(), i); if (g[t].end() - it < k) { return -1; } else { return *(it + k - 1); } }; for (int i = 0; i < n; ++i) { if (s[i] == 'J') { int x = i - 1; for (int t = 0; t < 3; ++t) { x = nxt(t, x); if (x == -1) { break; } } if (x != -1) { ans = min(ans, i + (n - x - 1)); } } } cout << (ans == n ? -1 : ans); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...