Submission #1300186

#TimeUsernameProblemLanguageResultExecution timeMemory
1300186hynmjJJOOII 2 (JOI20_ho_t2)C++20
0 / 100
0 ms332 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const long long N = 2e5 + 5; int a[N]; int n, k; int p1[N]; int p2[N]; int p3[N]; void solve() { int n, k; string s; cin >> n >> k >> s; for (int i = 1; i <= n; i++) { if (s[i - 1] == 'J') p1[i]++; else if (s[i - 1] == 'O') p2[i]++; else p3[i]++; p1[i] += p1[i - 1]; p2[i] += p2[i - 1]; p3[i] += p3[i - 1]; } for (int i = 0; i <= n; i++) { cout << p1[i] << ' '; } cout << endl; for (int i = 0; i <= n; i++) { cout << p2[i] << ' '; } cout << endl; for (int i = 0; i <= n; i++) { cout << p3[i] << ' '; } cout << endl; // cout << endl; int j = 0; int ans = 1e18; for (int i = 0; i <= n; i++) { // jjs int next = lower_bound(p1, p1 + n + 1, p1[i] + k) - p1; int J = next; next = lower_bound(p2, p2 + n + 1, p2[next] + k) - p2; int O = next; next = lower_bound(p3, p3 + n + 1, p3[next] + k) - p3; int I = next; // cout << J << ' ' << O << ' ' << I << endl; if (p1[J] - p1[i] >= k and p2[O] - p2[J] >= k and p3[I] - p3[O] >= k) ans = min(ans, next - i); } cout << ((ans == 1e18) ? -1 : ans - 3 * k); } signed main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int t = 1; // cin >> t; for (int i = 1; i <= t; i++) { // cout << "Case #" << i << ':' << ' '; solve(); cout << endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...