Submission #273017

#TimeUsernameProblemLanguageResultExecution timeMemory
273017ChrisTJJOOII 2 (JOI20_ho_t2)C++17
100 / 100
31 ms2048 KiB
#include <bits/stdc++.h>
using namespace std;
char s[200'005];
int main() {
	int n,k;
	scanf ("%d %d",&n,&k);
	scanf ("%s",s+1);
	vector<int> js,os,is;
	for (int i = 1; i <= n; i++) {
		if (s[i] == 'J') js.push_back(i);
		else if (s[i] == 'O') os.push_back(i);
		else is.push_back(i);
	}
	int ret = 1e9;
	for (int i = 1; i <= n; i++) {
		int needJ = lower_bound(js.begin(),js.end(),i) - js.begin();
		needJ += k-1;
		if (needJ < (int)js.size()) {
			int pos = js[needJ];
			int needO = lower_bound(os.begin(),os.end(),pos) - os.begin();
			needO += k-1;
			if (needO < (int)os.size()) {
				pos = os[needO];
				int needI = lower_bound(is.begin(),is.end(),pos) - is.begin();
				needI += k-1;
				if (needI < (int)is.size()) {
					pos = is[needI];
					ret = min(ret,n - (i-1) - (n-pos) - k*3);
				}
			}
		}
	} 
	printf ("%d\n",ret<1e9?ret:-1);
    return 0;
}

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:6:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    6 |  scanf ("%d %d",&n,&k);
      |  ~~~~~~^~~~~~~~~~~~~~~
ho_t2.cpp:7:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    7 |  scanf ("%s",s+1);
      |  ~~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...