Submission #1102081

#TimeUsernameProblemLanguageResultExecution timeMemory
1102081stdfloatJJOOII 2 (JOI20_ho_t2)C++17
100 / 100
13 ms2172 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define sz(v) (int)(v).size() #define all(v) (v).begin(), (v).end() int f(char c) { return (c == 'J' ? 0 : 1 + (c == 'I')); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, k; string s; cin >> n >> k >> s; vector<int> v[3]; for (int i = 0; i < n; i++) v[f(s[i])].push_back(i); int mn = n; for (int i = 0; i < n; i++) { if (s[i] != 'J') continue; int x = i - 1; for (int j = 0; j < 3; j++) { x = upper_bound(all(v[j]), x) - v[j].begin(); if (x + k > sz(v[j])) { x = n; break; } x = v[j][x + k - 1]; } if (x == n) break; mn = min(mn, x - i); } cout << (mn == n ? -1 : mn + 1 - 3 * k); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...