#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--)
#define BIT(mask,i) ((mask >> i) & 1ll )
#define endl '\n'
#define all(x) x.begin(),x.end()
#define ii pair <int,int>
using namespace std;
#define read doc()
int doc () {bool minus = false;int result = 0;char ch;ch = getchar();while (true) {if (ch == '-') break;if (ch >= '0' && ch <= '9') break;ch = getchar();}if (ch == '-') minus = true; else result = ch-'0';while (true) {ch = getchar();if (ch < '0' || ch > '9') break;result = result*10 + (ch - '0');}if (minus)return -result;else return result;}
template<class X, class Y>bool minimize(X &x, const Y &y) {if (x > y) {x = y;return true;} else return false;}
template<class X, class Y>bool maximize(X &x, const Y &y) {if (x < y) {x = y;return true;} else return false;}
const long long oo = 1e18;
const int N = 1e6+5;
const int MOD = 1e9+7;
char a[N];
vector <int> J,O,I;
void Whyalwaysmezzz()
{
int n,k;
cin >> n >> k;
FOR(i,1,n) cin >> a[i];
FOR(i,1,n)
{
if (a[i] == 'J') J.push_back(i);
if (a[i] == 'O') O.push_back(i);
if (a[i] == 'I') I.push_back(i);
}
int ans = oo;
FOR(i,0,J.size()-1)
{
if (i + k - 1 > (int)J.size()-1) break;
int pos1 = J[i+k-1];
auto it2 = lower_bound(all(O),pos1);
if (it2 == O.end()) break;
int pos2 = it2 - O.begin();
if (pos2 + k - 1 > O.size()-1) break;
// pos2=O[pos2];
auto it3 = lower_bound(all(I),O[pos2+k-1]);
if (it3 == I.end()) break;
int pos3 = it3 - I.begin();
if (pos3 + k -1 > I.size()-1) break;
pos3 = pos3+k-1;
// cout << J[i] << " " << O[pos2] << " " << I[pos3] << endl;
ans = min(ans , I[pos3] - J[i] + 1 - k * 3);
}
cout << ans;
return;
}
#define TASK "task"
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);//freopen(TASK".inp","r",stdin);freopen(TASK".out","w",stdout);
int Sty1e = 1;
// cin >> Sty1e;
while (Sty1e--) Whyalwaysmezzz();
return 0;
}
Compilation message
ho_t2.cpp: In function 'void Whyalwaysmezzz()':
ho_t2.cpp:40:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | if (pos2 + k - 1 > O.size()-1) break;
| ~~~~~~~~~~~~~^~~~~~~~~~~~
ho_t2.cpp:45:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | if (pos3 + k -1 > I.size()-1) break;
| ~~~~~~~~~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |