답안 #560969

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
560969 2022-05-12T06:18:49 Z Aktan JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
12 ms 3300 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template<class T>
using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define int long long
#define ft first
#define sc second
const int mod=1e9+7,INF=1e17,N=1e5;

main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 int n,k;
 cin >> n >> k;
 string s;
 cin >> s;
 int ans=INF;
 vector<int> a,b,c;
 for(int i=0;i<n;i++){
 	if(s[i]=='J'){
 		a.push_back(i);
	 }
	 else if(s[i]=='O'){
	 	b.push_back(i);
	 }
	 else{
	 	c.push_back(i);
	 }
 }
 for(int i=k-1;i<b.size();i++){
 	int l=b[i-k+1],r=b[i];
 	int x=--lower_bound(a.begin(),a.end(),l)-a.begin(),y=lower_bound(c.begin(),c.end(),r)-c.begin();	
 	x-=k;
 	x++;
 	y+=k;
 	y--;
 	if(x>=0 && y<c.size()){
 		ans=min(ans,(c[y]-a[x]+1)-(k*3));
	 }
 }
 if(ans==INF){
 	cout << -1;
 	return 0;
 }
 cout << ans;
}



Compilation message

ho_t2.cpp:13:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   13 | main(){
      | ^~~~
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:32:17: 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]
   32 |  for(int i=k-1;i<b.size();i++){
      |                ~^~~~~~~~~
ho_t2.cpp:39:15: 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]
   39 |   if(x>=0 && y<c.size()){
      |              ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 316 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 316 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 316 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 316 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 316 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 316 KB Output is correct
32 Correct 1 ms 320 KB Output is correct
33 Correct 1 ms 316 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 316 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 316 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 316 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 316 KB Output is correct
32 Correct 1 ms 320 KB Output is correct
33 Correct 1 ms 316 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 12 ms 2372 KB Output is correct
37 Correct 12 ms 2892 KB Output is correct
38 Correct 11 ms 2840 KB Output is correct
39 Correct 11 ms 2984 KB Output is correct
40 Correct 9 ms 3020 KB Output is correct
41 Correct 10 ms 2992 KB Output is correct
42 Correct 11 ms 2896 KB Output is correct
43 Correct 5 ms 1772 KB Output is correct
44 Correct 6 ms 2116 KB Output is correct
45 Correct 9 ms 2952 KB Output is correct
46 Correct 10 ms 3092 KB Output is correct
47 Correct 9 ms 2996 KB Output is correct
48 Correct 10 ms 2992 KB Output is correct
49 Correct 6 ms 1836 KB Output is correct
50 Correct 8 ms 2992 KB Output is correct
51 Correct 8 ms 3020 KB Output is correct
52 Correct 5 ms 2368 KB Output is correct
53 Correct 6 ms 2888 KB Output is correct
54 Correct 5 ms 3300 KB Output is correct
55 Correct 4 ms 3300 KB Output is correct
56 Correct 3 ms 3288 KB Output is correct