제출 #286151

#제출 시각아이디문제언어결과실행 시간메모리
286151reymontada61JJOOII 2 (JOI20_ho_t2)C++14
100 / 100
43 ms2056 KiB
#include <bits/stdc++.h>
using namespace std;

int n, k;
string s;
vector<int> tr[3];

int start(int at) {
	int jind = lower_bound(tr[0].begin(), tr[0].end(), at) - tr[0].begin();
	if (jind + k >= tr[0].size()) return INT_MAX;
	int oind = lower_bound(tr[1].begin(), tr[1].end(), tr[0][jind+k]) - tr[1].begin();
	if (oind + k >= tr[1].size()) return INT_MAX;
	int iind = lower_bound(tr[2].begin(), tr[2].end(), tr[1][oind+k]) - tr[2].begin();
	if (iind + k >= tr[2].size()) return INT_MAX;
	return tr[2][iind+k];
}

signed main() {

	cin >> n >> k;
	cin >> s;
	k--;

	for (int i=1; i<=n; i++) {
		if (s[i-1] == 'J') tr[0].push_back(i);
		if (s[i-1] == 'O') tr[1].push_back(i);
		if (s[i-1] == 'I') tr[2].push_back(i);
	}
	
	int le = INT_MAX;
	
	for (int i=1; i<=n; i++) {
		le = min(le, start(i) - i + 1);
	}
	
	if (le > n) {
		cout << -1 << endl;
	} 
	else {
		cout << le - 3 * (k+1) << endl;
	}

}

컴파일 시 표준 에러 (stderr) 메시지

ho_t2.cpp: In function 'int start(int)':
ho_t2.cpp:10:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |  if (jind + k >= tr[0].size()) return INT_MAX;
      |      ~~~~~~~~~^~~~~~~~~~~~~~~
ho_t2.cpp:12:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |  if (oind + k >= tr[1].size()) return INT_MAX;
      |      ~~~~~~~~~^~~~~~~~~~~~~~~
ho_t2.cpp:14:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  if (iind + k >= tr[2].size()) return INT_MAX;
      |      ~~~~~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...