답안 #503581

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
503581 2022-01-08T11:10:26 Z lucri JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
17 ms 1264 KB
#include <iostream>
using namespace std;
int n,k,pj[200010],po[200010],pi[200010],aj,ao,ai,nrj,nro,nri,ans=-1;
char c;
int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;++i)
    {
        cin>>c;
        if(c=='J')
            pj[++nrj]=i;
        if(c=='O')
            po[++nro]=i;
        if(c=='I')
            pi[++nri]=i;
    }
    int c=nri,a=nrj,b=nro;
    for(int c=nri;c>=k;--c)
    {
        while(pi[c-k+1]<po[b])
            --b;
        if(b<k)
            break;
        while(po[b-k+1]<pj[a])
            --a;
        if(a<k)
            break;
        if(ans==-1||ans>pi[c]-pj[a-k+1]+1-3*k)
            ans=pi[c]-pj[a-k+1]+1-3*k;
    }
    cout<<ans;
    return 0;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:18:9: warning: unused variable 'c' [-Wunused-variable]
   18 |     int c=nri,a=nrj,b=nro;
      |         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 292 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 1 ms 292 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 292 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 1 ms 292 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 280 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 300 KB Output is correct
20 Correct 1 ms 300 KB Output is correct
21 Correct 2 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 276 KB Output is correct
24 Correct 1 ms 292 KB Output is correct
25 Correct 1 ms 284 KB Output is correct
26 Correct 1 ms 280 KB Output is correct
27 Correct 1 ms 276 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 288 KB Output is correct
31 Correct 1 ms 300 KB Output is correct
32 Correct 1 ms 296 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 292 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 1 ms 292 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 280 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 300 KB Output is correct
20 Correct 1 ms 300 KB Output is correct
21 Correct 2 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 276 KB Output is correct
24 Correct 1 ms 292 KB Output is correct
25 Correct 1 ms 284 KB Output is correct
26 Correct 1 ms 280 KB Output is correct
27 Correct 1 ms 276 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 288 KB Output is correct
31 Correct 1 ms 300 KB Output is correct
32 Correct 1 ms 296 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 13 ms 1184 KB Output is correct
37 Correct 14 ms 1224 KB Output is correct
38 Correct 14 ms 1220 KB Output is correct
39 Correct 14 ms 1200 KB Output is correct
40 Correct 15 ms 1216 KB Output is correct
41 Correct 15 ms 1184 KB Output is correct
42 Correct 14 ms 1228 KB Output is correct
43 Correct 8 ms 828 KB Output is correct
44 Correct 11 ms 972 KB Output is correct
45 Correct 14 ms 1264 KB Output is correct
46 Correct 13 ms 1172 KB Output is correct
47 Correct 13 ms 1220 KB Output is correct
48 Correct 17 ms 1256 KB Output is correct
49 Correct 10 ms 864 KB Output is correct
50 Correct 15 ms 1200 KB Output is correct
51 Correct 14 ms 1204 KB Output is correct
52 Correct 13 ms 1208 KB Output is correct
53 Correct 13 ms 1220 KB Output is correct
54 Correct 12 ms 1184 KB Output is correct
55 Correct 12 ms 1220 KB Output is correct
56 Correct 13 ms 1172 KB Output is correct