제출 #1165731

#제출 시각아이디문제언어결과실행 시간메모리
1165731TsaganaJJOOII 2 (JOI20_ho_t2)C++20
100 / 100
4 ms3016 KiB
#include<bits/stdc++.h> #define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie(); #define all(x) x.begin(), x.end() #define int long long #define pq priority_queue #define eb emplace_back #define lb lower_bound #define ub upper_bound #define pb push_back #define pp pop_back #define F first #define S second using namespace std; void solve () { int n, k; string str; cin >> n >> k >> str; vector<vector<int>> pos(3); vector<int> last(4, -1e9); map<char, int> id = {{'J', 0}, {'O', 1}, {'I', 2}}; int ans = 1e9; for (int i = 0; i < n; i++) { last[0] = i; int x = id[str[i]]; pos[x].pb(last[x]); if (pos[x].size() >= k) last[x + 1] = pos[x][pos[x].size() - k]; ans = min(ans, i - last[3] + 1 - 3 * k); } if (ans > n) ans = -1; cout << ans << '\n'; } signed main() {IOS solve(); return 0;}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...