Submission #535741

#TimeUsernameProblemLanguageResultExecution timeMemory
535741abc864197532JJOOII 2 (JOI20_ho_t2)C++17
100 / 100
33 ms2052 KiB
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define pii pair<int,int>
#define X first
#define Y second
#define all(x) x.begin(), x.end()
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T i, U ...j) {
	cout << i << ' ', abc(j...);
}
template <typename T> void printv(T l, T r) {
	for (; l != r; ++l)
		cout << *l << " \n"[l + 1 == r];
}
#ifdef Doludu
#define test(x...) abc("[" + string(#x) + "]", x)
#define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#else
#define test(x...) void(0)
#define owo ios::sync_with_stdio(false), cin.tie(0)
#endif

int main () {
	owo;
	int n, k;
	string s;
	cin >> n >> k >> s;
	vector <int> pos[3];
	for (int i = 0; i < n; ++i) {
		if (s[i] == 'J')
			pos[0].pb(i);
		else if (s[i] == 'O')
			pos[1].pb(i);
		else
			pos[2].pb(i);
	}
	int ans = 1 << 30;
	for (int i = 0; i < n; ++i) {
		int now = i;
		for (int j : {0, 1, 2}) {
			auto it = lower_bound(all(pos[j]), now) - pos[j].begin() + k - 1;
			if (it < pos[j].size())
				now = pos[j][it];
			else {
				now = n;
				break;
			}
		}
		if (now < n)
			ans = min(ans, now - i + 1);
	}
	cout << (ans == 1 << 30 ? -1 : ans - k * 3) << '\n';
}

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:46:11: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |    if (it < pos[j].size())
      |        ~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...