답안 #716749

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
716749 2023-03-31T02:15:55 Z chenyan JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
5 ms 864 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
#define N 200010
int ans=1e9;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,k,i,j,a,b,c,d,e,f,o;
	cin>>n>>k;
	string s;
	cin>>s;
	for(a=-1,b=-1,c=-1,d=-1,e=-1,f=-1,i=0,j=0,o=0;;){
		while(b<n&&j<k){
			if(s[++b]=='J')j++;
		}
		while(c<=b){
			if(c>=0&&s[c]=='O')o--;
			c++;
		}
		while(d<n&&o<k){
			if(s[++d]=='O')o++;
		}
		while(e<=d){
			if(e>=0&&s[e]=='I')i--;
			e++;
		}
		while(f<n&&i<k){
			if(s[++f]=='I')i++;
		}
		if(f==n)break;
		ans=min(f+d+b-e-c-a-3*k+3,ans);
		if(a>=0&&s[a]=='J')j--;
		a++;
	}
	cout<<(ans==1e9?-1:ans)<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 0 ms 316 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 0 ms 316 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 320 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 320 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 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 320 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 0 ms 316 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 320 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 320 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 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 320 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 4 ms 852 KB Output is correct
37 Correct 4 ms 840 KB Output is correct
38 Correct 4 ms 852 KB Output is correct
39 Correct 4 ms 864 KB Output is correct
40 Correct 2 ms 852 KB Output is correct
41 Correct 4 ms 836 KB Output is correct
42 Correct 5 ms 864 KB Output is correct
43 Correct 1 ms 564 KB Output is correct
44 Correct 2 ms 824 KB Output is correct
45 Correct 2 ms 852 KB Output is correct
46 Correct 1 ms 844 KB Output is correct
47 Correct 2 ms 852 KB Output is correct
48 Correct 2 ms 852 KB Output is correct
49 Correct 2 ms 724 KB Output is correct
50 Correct 2 ms 852 KB Output is correct
51 Correct 2 ms 852 KB Output is correct
52 Correct 2 ms 828 KB Output is correct
53 Correct 2 ms 840 KB Output is correct
54 Correct 2 ms 864 KB Output is correct
55 Correct 2 ms 852 KB Output is correct
56 Correct 2 ms 852 KB Output is correct