Submission #1086499

#TimeUsernameProblemLanguageResultExecution timeMemory
1086499toast12JJOOII 2 (JOI20_ho_t2)C++14
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; string s; cin >> s; int j = 0, o = 0, i = 0; for (int idx = 0; idx < n; idx++) { if (s[idx] == 'J' && j < k) j++; else if (s[idx] == 'O' && j == k && o < k) o++; else if (s[idx] == 'I' && j == k && o == k && i < k) i++; } if (j != k || o != k || i != k) { cout << "-1\n"; return 0; } int ans1 = 0; j = 0, o = 0, i = 0; for (int idx = 0; idx < n; idx++) { if (j == k && o == k && i == k) break; if (s[idx] == 'J' && j < k) j++; else if (s[idx] == 'O' && j == k && o < k) o++; else if (s[idx] == 'I' && j == k && o == k && i < k) i++; else { if (j || o || i) ans1++; } } int ans2 = 0; j = 0, o = 0, i = 0; for (int idx = n-1; idx >= 0; idx--) { if (j == k && o == k && i == k) break; if (s[idx] == 'I' && i < k) i++; else if (s[idx] == 'O' && i == k && o < k) o++; else if (s[idx] == 'J' && i == k && o == k && j < k) j++; else { if (j || o || i) ans2++; } } cout << min(ans1, ans2) << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...