# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
757551 |
2023-06-13T10:12:26 Z |
vjudge1 |
JJOOII 2 (JOI20_ho_t2) |
C++17 |
|
6 ms |
6584 KB |
//
// main.cpp
// HAZ
//
// Created by Nurbek Nurbagi
//
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long double ld;
typedef long long ll;
using namespace std;
int gcd (int a, int b) {
while (b) {
a %= b;
swap (a, b);
}
return a;
}
const ll N = 2e5 + 7;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
const ld pi = 3.141592653589793;
const ld eps = 1e-12;
const ll zero = 0;
const int A = 1e9 + 5;
const int dx[4] = {0, -1, 0, 0};
const int dy[4] = {1, 0, -1, 1};
vector <ll> j(N), o(N), i(N);
ll get (int k, int mn, ll l, ll r, char c) {
vector <ll> d;
if (c == 'j') d = j;
if (c == 'o') d = o;
if (c == 'i') d = i;
int x = 0;
while (l <= r) {
int mid = (l + r) / 2;
if (d[mid] >= mn){
r = mid - 1;
x = mid;
}
else l = mid + 1;
}
return x;
}
void solve() {
int n, k;
cin >> n >> k;
string s;
cin >> s;
j[0] = (s[1] == 'J');
o[0] = (s[1] == 'O');
i[0] = (s[1] == 'I');
for (int q = 1; q < n; q++) {
j[q] = j[q - 1] + (s[q] == 'J');
o[q] = o[q - 1] + (s[q] == 'O');
i[q] = i[q - 1] + (s[q] == 'I');
}
ll mx = 1e18;
for (int q = 0; q < n; q++) {
if (s[q] != 'J') continue;
int x = j[q] + k - 1;
ll cnt = get(k, x, q, n, 'j');
if (!cnt) break;
x = o[cnt] + k;
ll cnt2 = get(k, x, cnt + 1, n, 'o');
if (!cnt2) break;
x = i[cnt2] + k;
ll cnt3 = get(k, x, cnt2 + 1, n + 1, 'i');
if (!cnt3) break;
mx = min((cnt3 - q + 1) - 3 * k, mx);
}
if (mx == 1e18) {
cout << -1;
return;
}
cout << mx;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// freopen("herding.in","r",stdin);
// freopen("herding.out","w",stdout);
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
6504 KB |
Output is correct |
2 |
Correct |
6 ms |
6584 KB |
Output is correct |
3 |
Correct |
5 ms |
6584 KB |
Output is correct |
4 |
Incorrect |
3 ms |
6484 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
6504 KB |
Output is correct |
2 |
Correct |
6 ms |
6584 KB |
Output is correct |
3 |
Correct |
5 ms |
6584 KB |
Output is correct |
4 |
Incorrect |
3 ms |
6484 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
6504 KB |
Output is correct |
2 |
Correct |
6 ms |
6584 KB |
Output is correct |
3 |
Correct |
5 ms |
6584 KB |
Output is correct |
4 |
Incorrect |
3 ms |
6484 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |