답안 #557250

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
557250 2022-05-05T04:46:02 Z krit3379 JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
11 ms 1996 KB
#include<bits/stdc++.h>
using namespace std;
#define N 200005

int nxt,ans=1e9;
char s[N];
vector<int> v[4];

int main(){
    int n,k,i;
    scanf("%d %d %s",&n,&k,s+1);
    for(i=1;i<=n;i++){
        if(s[i]=='J')v[1].push_back(i);
        else if(s[i]=='O')v[2].push_back(i);
        else v[3].push_back(i);
    }
    for(i=0;i<v[1].size();i++){
        nxt=i+k-1;
        if(nxt>=v[1].size())break;
        nxt=lower_bound(v[2].begin(),v[2].end(),v[1][nxt])-v[2].begin()+k-1;
        if(nxt>=v[2].size())break;
        nxt=lower_bound(v[3].begin(),v[3].end(),v[2][nxt])-v[3].begin()+k-1;
        if(nxt>=v[3].size())break;
        ans=min(ans,v[3][nxt]-v[1][i]+1-3*k);
    }
    if(ans==1e9)printf("-1");
    else printf("%d",ans);
    return 0;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:17:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for(i=0;i<v[1].size();i++){
      |             ~^~~~~~~~~~~~
ho_t2.cpp:19:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |         if(nxt>=v[1].size())break;
      |            ~~~^~~~~~~~~~~~~
ho_t2.cpp:21:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |         if(nxt>=v[2].size())break;
      |            ~~~^~~~~~~~~~~~~
ho_t2.cpp:23:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         if(nxt>=v[3].size())break;
      |            ~~~^~~~~~~~~~~~~
ho_t2.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     scanf("%d %d %s",&n,&k,s+1);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 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 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 308 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 340 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 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 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 308 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 340 KB Output is correct
14 Correct 0 ms 212 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 340 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 340 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 212 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 304 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 340 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 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 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 340 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 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 308 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 340 KB Output is correct
14 Correct 0 ms 212 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 340 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 340 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 212 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 304 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 340 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 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 9 ms 1488 KB Output is correct
37 Correct 10 ms 1808 KB Output is correct
38 Correct 10 ms 1932 KB Output is correct
39 Correct 9 ms 1956 KB Output is correct
40 Correct 5 ms 1772 KB Output is correct
41 Correct 8 ms 1872 KB Output is correct
42 Correct 11 ms 1876 KB Output is correct
43 Correct 3 ms 1236 KB Output is correct
44 Correct 4 ms 1364 KB Output is correct
45 Correct 4 ms 1984 KB Output is correct
46 Correct 4 ms 1868 KB Output is correct
47 Correct 4 ms 1856 KB Output is correct
48 Correct 5 ms 1980 KB Output is correct
49 Correct 3 ms 1360 KB Output is correct
50 Correct 4 ms 1840 KB Output is correct
51 Correct 5 ms 1852 KB Output is correct
52 Correct 3 ms 1488 KB Output is correct
53 Correct 4 ms 1876 KB Output is correct
54 Correct 4 ms 1884 KB Output is correct
55 Correct 3 ms 1996 KB Output is correct
56 Correct 3 ms 1888 KB Output is correct