제출 #1151237

#제출 시각아이디문제언어결과실행 시간메모리
1151237KK_1729JJOOII 2 (JOI20_ho_t2)C++17
0 / 100
0 ms324 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define pb push_back #define all(a) a.begin(), a.end() #define endl "\n" void printVector(vector<int> a){ for (auto x: a) cout << x << " "; cout << endl; } void solve(){ int n, k; cin >> n >> k; string s; cin >> s; vector<int> j; vector<int> o; vector<int> i; FOR(b,0,n){ if (s[b] == 'J') j.pb(b); else if (s[b] == 'O') o.pb(b); else i.pb(b); } FOR(b,0,n){ j.pb(n+1); o.pb(n+1); i.pb(n+1); } int ans = n+1; bool can = false; if (j.size() == 0 || o.size() == 0 || i.size() == 0){ cout << -1 << endl; return; } FOR(b,0,1){ auto ind = (lower_bound(all(j), b) - j.begin()); if (j[ind] < b) continue; int jc = j[ind+k-1]; if (jc > n) break; // cout << ind << jc << endl; auto ind1 = (lower_bound(all(o), jc) - o.begin()); if (o[ind1] < jc) continue; int oc = o[ind1+k-1]; if (oc > n) break; // cout << ind1 << oc << endl; auto ind2 = (lower_bound(all(i), oc) - i.begin()); if (i[ind2] < oc) continue; int ic = i[ind2+k-1]; // cout << ic << endl; if (ic < n){ can = true; ans = min(ans, ic-j[ind]+1-3*k); } } if (can) cout << ans << endl; else cout << -1 << endl; } int32_t main(){ ios::sync_with_stdio(false);cin.tie(nullptr); int t = 1; // cin >> t; while (t--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...