제출 #260206

#제출 시각아이디문제언어결과실행 시간메모리
260206cheissmartJJOOII 2 (JOI20_ho_t2)C++14
100 / 100
12 ms2052 KiB
#include <bits/stdc++.h> #define F first #define S second #define PB push_back #define EB emplace_back #define MP make_pair #define ALL(v) (v).begin(), (v).end() #define debug(x) cerr << #x << " " << (x) << endl; #define V vector using namespace std; typedef long long ll; typedef pair<int, int> pi; typedef V<int> vi; int main() { ios::sync_with_stdio(0); cin.tie(0); int k, n; string s; cin >> n >> k >> s; int mx = -1; vi js, os, is; for(int i = 0; i < n; i++) { if(s[i] == 'J') js.PB(i); else if(s[i] == 'O') os.PB(i); else is.PB(i); } for(int i = 0; i + k - 1 < (int)js.size(); i++) { int j = js[i + k - 1]; j = lower_bound(ALL(os), j) - os.begin(); if(j + k - 1 >= (int)os.size()) break; j = os[j + k - 1]; j = lower_bound(ALL(is), j) - is.begin(); if(j + k - 1 >= (int)is.size()) break; j = is[j + k - 1]; mx = max(mx, js[i] + n - 1 - j); } if(mx == -1) cout << -1 << endl; else { cout << n-mx-3*k << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...