답안 #991549

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
991549 2024-06-02T12:06:22 Z vicvic JJOOII 2 (JOI20_ho_t2) C++11
100 / 100
10 ms 2096 KB
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
using namespace std;
const int nmax=2e5;
int n, k;
string s;
vector <int> poz_j, poz_o, poz_i;
int main()
{
    cin >> n >> k >> s;
    for (int i=0;s[i];i++)
    {
        if (s[i]=='J')
        {
            poz_j.push_back (i);
        }
        else if (s[i]=='O')
        {
            poz_o.push_back (i);
        }
        else poz_i.push_back (i);
    }
    if (poz_j.size()<k || poz_i.size()<k || poz_o.size()<k)
    {
        cout << -1;
        return 0;
    }
    bool found_sol=0;
    int ret=nmax+5;
    for (int i=k-1;i<poz_j.size();i++)
    {
        int rez_o=-1, st=0, dr=poz_o.size()-1;
        while (st<=dr)
        {
            int mij = (st+dr) >> 1;
            if (poz_o[mij]<=poz_j[i])
            {
                rez_o=mij;
                st=mij+1;
            }
            else dr=mij-1;
        }
        rez_o+=k;
        if (rez_o>poz_o.size()-1)
        {
            break;
        }
        int rez_i=-1;
        st=0, dr=poz_i.size()-1;
        while (st<=dr)
        {
            int mij = (st+dr) >> 1;
            if (poz_i[mij]<=poz_o[rez_o])
            {
                rez_i=mij;
                st=mij+1;
            }
            else dr=mij-1;
        }
        rez_i+=k;
        if (rez_i>poz_i.size()-1)
        {
            break;
        }
        int rez_j=i-k+1;
        found_sol=1;
        ret=min (ret, poz_i[rez_i]-poz_j[rez_j]+1-3*k);
    }
    if (!found_sol)
    {
        cout << -1;
        return 0;
    }
    cout << ret;
    return 0;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:25:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   25 |     if (poz_j.size()<k || poz_i.size()<k || poz_o.size()<k)
      |         ~~~~~~~~~~~~^~
ho_t2.cpp:25:39: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   25 |     if (poz_j.size()<k || poz_i.size()<k || poz_o.size()<k)
      |                           ~~~~~~~~~~~~^~
ho_t2.cpp:25:57: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   25 |     if (poz_j.size()<k || poz_i.size()<k || poz_o.size()<k)
      |                                             ~~~~~~~~~~~~^~
ho_t2.cpp:32:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for (int i=k-1;i<poz_j.size();i++)
      |                    ~^~~~~~~~~~~~~
ho_t2.cpp:46:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         if (rez_o>poz_o.size()-1)
      |             ~~~~~^~~~~~~~~~~~~~~
ho_t2.cpp:63:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |         if (rez_i>poz_i.size()-1)
      |             ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 420 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 420 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 9 ms 1632 KB Output is correct
37 Correct 9 ms 1828 KB Output is correct
38 Correct 9 ms 2096 KB Output is correct
39 Correct 10 ms 2048 KB Output is correct
40 Correct 6 ms 2020 KB Output is correct
41 Correct 8 ms 1956 KB Output is correct
42 Correct 10 ms 2016 KB Output is correct
43 Correct 4 ms 1376 KB Output is correct
44 Correct 4 ms 1468 KB Output is correct
45 Correct 5 ms 2020 KB Output is correct
46 Correct 5 ms 2008 KB Output is correct
47 Correct 5 ms 2016 KB Output is correct
48 Correct 5 ms 2016 KB Output is correct
49 Correct 3 ms 1468 KB Output is correct
50 Correct 6 ms 1892 KB Output is correct
51 Correct 5 ms 1760 KB Output is correct
52 Correct 5 ms 1688 KB Output is correct
53 Correct 5 ms 1748 KB Output is correct
54 Correct 6 ms 2024 KB Output is correct
55 Correct 5 ms 2020 KB Output is correct
56 Correct 4 ms 2024 KB Output is correct