답안 #312496

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
312496 2020-10-13T14:42:41 Z quocnguyen1012 JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
39 ms 3400 KB
#include<bits/stdc++.h>
 
using namespace std;
 
const int N=2e5+5;
string s;
int n,k,sum[3][N];
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n>>k;
    cin>>s;
    s="."+s;
    for(int i=1;i<=n;i++)
    {
        sum[0][i]=sum[0][i-1]+(s[i]=='J');
        sum[1][i]=sum[1][i-1]+(s[i]=='O');
        sum[2][i]=sum[2][i-1]+(s[i]=='I');
    }
    int res=-1;
    for(int i=1;i<=n-3*k+1;i++)
    {
        bool kt=true;
        int cur=i;
        for(int j=0;j<3;j++)
        {
            int to=lower_bound(sum[j]+1,sum[j]+n+1,sum[j][cur-1]+k)-sum[j];
            if(to>n) kt=false;
            cur=to+1;
        }
        if(!kt) continue;
        if(res==-1||res>(cur-i)-3*k) res=(cur-i)-3*k;
    }
    cout<<res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 31 ms 3028 KB Output is correct
37 Correct 33 ms 3144 KB Output is correct
38 Correct 39 ms 3144 KB Output is correct
39 Correct 36 ms 3144 KB Output is correct
40 Correct 22 ms 3400 KB Output is correct
41 Correct 29 ms 3144 KB Output is correct
42 Correct 37 ms 3168 KB Output is correct
43 Correct 12 ms 2304 KB Output is correct
44 Correct 15 ms 2548 KB Output is correct
45 Correct 20 ms 3144 KB Output is correct
46 Correct 19 ms 3144 KB Output is correct
47 Correct 19 ms 3144 KB Output is correct
48 Correct 19 ms 3144 KB Output is correct
49 Correct 13 ms 2312 KB Output is correct
50 Correct 19 ms 3144 KB Output is correct
51 Correct 19 ms 3144 KB Output is correct
52 Correct 6 ms 3152 KB Output is correct
53 Correct 7 ms 3144 KB Output is correct
54 Correct 22 ms 3144 KB Output is correct
55 Correct 9 ms 3272 KB Output is correct
56 Correct 3 ms 3144 KB Output is correct