제출 #1315910

#제출 시각아이디문제언어결과실행 시간메모리
1315910kkkkkJJOOII 2 (JOI20_ho_t2)C++20
100 / 100
13 ms3004 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int N = 2e5 + 11; const int inf = 1e18 + 7; vector < int > pos[91]; signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, k; string s; cin >> n >> k >> s; for(int i = 0; i < n; i++){ pos[s[i]].push_back(i); } int ans = n + 1; for(int i = 0; i < n; i++){ if(s[i] != 'J') continue; int J = lower_bound(pos['J'].begin(), pos['J'].end(), i) - pos['J'].begin(); if(J + k - 1 >= pos['J'].size()) break; int j = pos['J'][J + k - 1]; int O = lower_bound(pos['O'].begin(), pos['O'].end(), j) - pos['O'].begin(); if(O + k - 1 >= pos['O'].size()) break; j = pos['O'][O + k - 1]; int I = lower_bound(pos['I'].begin(), pos['I'].end(), j) - pos['I'].begin(); if(I + k - 1 >= pos['I'].size()) break; j = pos['I'][I + k - 1]; ans = min(ans, j - i + 1 - 3 * k); } if(ans == n + 1) ans = -1; cout << ans; } // subete no mono no owari wa sugu ni yattekuru
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...