Submission #1300169

#TimeUsernameProblemLanguageResultExecution timeMemory
1300169AbdullahIshfaqJJOOII 2 (JOI20_ho_t2)C++20
100 / 100
5 ms3156 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define MOD 998244353 void solve() { ll n, k; string str; cin >> n >> k >> str; vector<vector<ll>> pos(3); vector<ll> last(4, -1e9); map<char, ll> id = {{'J', 0}, {'O', 1}, {'I', 2}}; ll ans = 1e9; for (ll i = 0; i < n; i++) { last[0] = i; ll x = id[str[i]]; pos[x].emplace_back(last[x]); if (pos[x].size() >= k) last[x + 1] = pos[x][pos[x].size() - k]; ans = min(ans, i - last[3] + 1 - 3 * k); } if (ans > n) ans = -1; cout << ans << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll t = 1; // cin >> t; // cout << fixed << setprecision(12); for (ll i = 1; i <= t; i++) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...