답안 #996890

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
996890 2024-06-11T11:50:38 Z goduadzesaba JJOOII 2 (JOI20_ho_t2) C++17
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,k,ans,d,x; string s;
vector <int> j,o,_i;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
	cin>>n>>k>>s;
	for (int i=0; i<n; i++){
		if (s[i]=='J'){
			j.push_back(i+1);
		}
		if (s[i]=='O'){
			o.push_back(i+1);
		}
		if (s[i]=='I'){
			_i.push_back(i+1);
		}
	} ans=1e9;
	for (int i=0; i<o.size()-k+1; i++){
		d=o[i+k-1]-o[i]-k+1;
		x=lower_bound(j.begin(),j.end(),o[i])-1-j.begin();
		if (x<k-1) continue;
		d+=j[x]-j[x-k+1]-k+1;
		x=lower_bound(_i.begin(),_i.end(),o[i+k-1])-_i.begin();
		if (x>(int)_i.size()-k) continue;
		d+=_i[x+k-1]-_i[x]-2;
		ans=min(ans,d);
	}
	cout<<(ans<1e9?ans:-1);
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:21:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |  for (int i=0; i<o.size()-k+1; i++){
      |                ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -