Submission #1131524

#TimeUsernameProblemLanguageResultExecution timeMemory
1131524lopkusJJOOII 2 (JOI20_ho_t2)C++20
100 / 100
1308 ms8592 KiB
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; vector<int> a(n + 1); vector<int> idx[4]; for(int i = 1; i <= n; i++) { char x; cin >> x; if(x == 'J') { a[i] = 1; } else if(x == 'O') { a[i] = 2; } else { a[i] = 3; } idx[a[i]].push_back(i); } vector<int> cnt1(n + 1, 0); vector<int> cnt2(n + 1, 0); vector<int> cnt3(n + 1, 0); for(int i = 1; i <= n; i++) { cnt1[i] = cnt1[i - 1]; cnt2[i] = cnt2[i - 1]; cnt3[i] = cnt3[i - 1]; if(a[i] == 1) { cnt1[i] += 1; } else if(a[i] == 2) { cnt2[i] += 1; } else { cnt3[i] += 1; } } int ans = n + 1; for(int i = 0; i + k - 1 < idx[1].size(); i++) { int l1 = idx[1][i]; int r1 = idx[1][i + k - 1]; int l2 = - 1; int r2 = - 1; for(int j = 0; j + k - 1 < idx[2].size(); j++) { if(idx[2][j] >= r1) { l2 = idx[2][j]; r2 = idx[2][j + k - 1]; break; } } int l3 = - 1; int r3 = - 1; for(int j = 0; j + k - 1 < idx[3].size(); j++) { if(idx[3][j] >= r2) { l3 = idx[3][j]; r3 = idx[3][j + k - 1]; break; } } if(l2 == - 1 || l3 == - 1) { continue; } ans = min(ans, r3 - l1 + 1 - 3 * k); } if(ans == n + 1) { cout << - 1; } else { cout << ans; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...