Submission #924507

#TimeUsernameProblemLanguageResultExecution timeMemory
924507qwe1rt1yuiop1JJOOII 2 (JOI20_ho_t2)C++14
100 / 100
15 ms2304 KiB
#include <bits/stdc++.h> // #define int long long using namespace std; using pii = pair<int, int>; void solve() { int n, k; string s; cin >> n >> k >> s; vector<int> pj, po, pi; for (int i = 0; i < n; ++i) { if (s[i] == 'J') pj.emplace_back(i); else if (s[i] == 'O') po.emplace_back(i); else pi.emplace_back(i); } int ans = INT_MAX; for (int i = n; i >= 0; --i) { if (i != n) { if (s[i] == 'J') pj.pop_back(); else if (s[i] == 'O') po.pop_back(); else pi.pop_back(); } if ((int)pi.size() < k) continue; int id = pi[(int)pi.size() - k]; id = lower_bound(po.begin(), po.end(), id) - po.begin(); if (id < k) continue; id -= k; id = lower_bound(pj.begin(), pj.end(), po[id]) - pj.begin(); if (id < k) continue; id -= k; ans = min(ans, i - pj[id]); } if (ans == INT_MAX) { cout << "-1\n"; return; } cout << ans - k * 3 << '\n'; } /* 10 2 OJIJOIOIIJ 9 3 JJJOOOIII 9 1 IIIOOOJJJ */ signed main() { ios::sync_with_stdio(0); cin.tie(0); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...