Submission #219574

# Submission time Handle Problem Language Result Execution time Memory
219574 2020-04-05T15:46:13 Z MKopchev JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
25 ms 1908 KB
#include<bits/stdc++.h>
using namespace std;

const int nmax=2e5+42;
int n,k;

vector<int> seen[3];

int ask(int pos,int where)
{
    if(where==3)return pos;
    pos++;
    int nxt_seen=lower_bound(seen[where].begin(),seen[where].end(),pos)-seen[where].begin();

    if(nxt_seen+k-1<seen[where].size())return ask(seen[where][nxt_seen+k-1],where+1);
    return 1e9;
}
int main()
{
    scanf("%i%i",&n,&k);

    for(int i=1;i<=n;i++)
    {
        char c=getchar();
        while(c!='J'&&c!='O'&&c!='I')c=getchar();

        if(c=='J')seen[0].push_back(i);
        else if(c=='O')seen[1].push_back(i);
        else seen[2].push_back(i);
    }

    int output=n+1;
    for(auto start:seen[0])
        output=min(output,ask(start-1,0)-start+1-3*k);

    if(output>n)printf("-1\n");
    else printf("%i\n",output);
    return 0;
}

Compilation message

ho_t2.cpp: In function 'int ask(int, int)':
ho_t2.cpp:15:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(nxt_seen+k-1<seen[where].size())return ask(seen[where][nxt_seen+k-1],where+1);
        ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i%i",&n,&k);
     ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Correct 4 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Correct 4 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 6 ms 384 KB Output is correct
33 Correct 4 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Correct 4 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 6 ms 384 KB Output is correct
33 Correct 4 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 20 ms 1404 KB Output is correct
37 Correct 23 ms 1660 KB Output is correct
38 Correct 22 ms 1660 KB Output is correct
39 Correct 21 ms 1788 KB Output is correct
40 Correct 19 ms 1660 KB Output is correct
41 Correct 20 ms 1660 KB Output is correct
42 Correct 25 ms 1660 KB Output is correct
43 Correct 13 ms 1276 KB Output is correct
44 Correct 14 ms 1276 KB Output is correct
45 Correct 18 ms 1656 KB Output is correct
46 Correct 18 ms 1776 KB Output is correct
47 Correct 17 ms 1660 KB Output is correct
48 Correct 18 ms 1908 KB Output is correct
49 Correct 13 ms 1280 KB Output is correct
50 Correct 18 ms 1660 KB Output is correct
51 Correct 18 ms 1660 KB Output is correct
52 Correct 13 ms 1404 KB Output is correct
53 Correct 14 ms 1660 KB Output is correct
54 Correct 15 ms 1784 KB Output is correct
55 Correct 13 ms 1784 KB Output is correct
56 Correct 12 ms 1784 KB Output is correct