답안 #701674

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
701674 2023-02-21T22:35:19 Z vjudge1 JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
6 ms 3288 KB
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long
#define inf ((int)1e18)
#define N 200005
using namespace std;

int32_t main(){
	fast
	int n, k, it=0;
	string s;
	cin>>n>>k>>s;
	int jc=0, oc=0, ic=0;
	for(; it<n; it++){
		if(s[it]=='J'){
			jc++;
			if(jc == k)break;
		}
	}
	for(; it<n; it++){
		if(s[it]=='O'){
			oc++;
			if(oc == k)break;
		}
	}
	for(; it<n; it++){
		if(s[it]=='I'){
			ic++;
			if(ic == k)break;
		}
	}
	if(ic != k){
		cout<<-1<<"\n";
		return 0;
	}
	vector <int> js, os, is;
	for(int i=0; i < n; i++){
		if(s[i] == 'J'){
			js.push_back(i);
		}
		if(s[i] == 'O'){
			os.push_back(i);
		}
		if(s[i] == 'I'){
			is.push_back(i);
		}
	}
	int jl=0, jr=k-1, ol=0, orr=0, il=0, ir=0;
	int ans=inf;
	while(js[jr] > os[ol]){
		ol++;
	}
	orr=ol+k-1;
	while(os[orr] > is[il]){
		il++;
	}
	ir=il+k-1;
	os.push_back(inf);
	is.push_back(inf);
	while(jr < js.size() and orr < os.size() and ir < is.size()){
		ans = min(ans, is[ir]-k*3-js[jl]+1);
		//cout<<ol<<" ";
		jr++;
		jl++;
		while(js[jr] > os[ol]){
			ol++;
		}
		orr=ol+k-1;
		while(os[orr] > is[il]){
			il++;
		}
		ir=il+k-1;
	}
	cout<<ans<<"\n";
}

Compilation message

ho_t2.cpp: In function 'int32_t main()':
ho_t2.cpp:60:11: 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]
   60 |  while(jr < js.size() and orr < os.size() and ir < is.size()){
      |        ~~~^~~~~~~~~~~
ho_t2.cpp:60:31: 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]
   60 |  while(jr < js.size() and orr < os.size() and ir < is.size()){
      |                           ~~~~^~~~~~~~~~~
ho_t2.cpp:60:50: 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]
   60 |  while(jr < js.size() and orr < os.size() and ir < is.size()){
      |                                               ~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 0 ms 316 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 0 ms 316 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 1 ms 316 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 0 ms 324 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 320 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 316 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 0 ms 316 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 1 ms 316 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 0 ms 324 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 320 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 316 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 6 ms 2380 KB Output is correct
37 Correct 6 ms 2864 KB Output is correct
38 Correct 6 ms 2884 KB Output is correct
39 Correct 5 ms 2976 KB Output is correct
40 Correct 6 ms 3020 KB Output is correct
41 Correct 5 ms 3020 KB Output is correct
42 Correct 6 ms 2892 KB Output is correct
43 Correct 4 ms 1772 KB Output is correct
44 Correct 4 ms 2000 KB Output is correct
45 Correct 5 ms 2960 KB Output is correct
46 Correct 5 ms 2960 KB Output is correct
47 Correct 5 ms 3020 KB Output is correct
48 Correct 5 ms 2964 KB Output is correct
49 Correct 1 ms 712 KB Output is correct
50 Correct 2 ms 844 KB Output is correct
51 Correct 2 ms 852 KB Output is correct
52 Correct 2 ms 852 KB Output is correct
53 Correct 2 ms 836 KB Output is correct
54 Correct 3 ms 3288 KB Output is correct
55 Correct 4 ms 3260 KB Output is correct
56 Correct 3 ms 3288 KB Output is correct