제출 #1322285

#제출 시각아이디문제언어결과실행 시간메모리
1322285aaaaaaaaJJOOII 2 (JOI20_ho_t2)C++20
1 / 100
1 ms332 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int inf = 1e18; signed main(){ ios::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); int n, k, ans = inf; string str; cin >> n >> k >> str; vector<int> dpje(n + 5, inf), dpof(n + 5, inf), dpoe(n + 5, inf), dpif(n + 5, inf); vector<char> pos[30]; for(int i = 0; i < (int) str.size(); ++i){ int key = str[i] - 'A'; pos[key].push_back(i); if(str[i] == 'J'){ if((int) pos[key].size() >= k){ dpje[i] = i - pos[key][(int) pos[key].size() - k] + 1 - k; } }else if(str[i] == 'O'){ if((int) pos['J' - 'A'].size()){ dpof[i] = dpje[pos['J' - 'A'].back()] + i - pos['J' - 'A'].back() - 1; } if((int) pos[key].size() >= k){ dpoe[i] = dpof[pos[key][(int) pos[key].size() - k]] + i - pos[key][(int) pos[key].size() - k] + 1 - k; } // cout << dpof[i] << " " << dpoe[i] << "\n"; }else{ if((int) pos['O' - 'A'].size()){ dpif[i] = dpoe[pos['O' - 'A'].back()] + i - pos['O' - 'A'].back() - 1; } if((int) pos[key].size() >= k){ ans = min(ans, dpif[pos[key][(int) pos[key].size() - k]] + i - pos[key][(int) pos[key].size() - k] + 1 - k); } } } cout << (ans >= inf ? -1 : ans) << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...