Submission #828869

# Submission time Handle Problem Language Result Execution time Memory
828869 2023-08-17T17:59:59 Z raphaelp JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
8 ms 3296 KB
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    vector<int> J(N, -1), O(N, -1), I(N, -1);
    deque<int> temp;
    for (int i = 0; i < N; i++)
    {
        if (S[i] == 'J')
            temp.push_back(i);
        if (temp.size() > K)
            temp.pop_front();
        if (temp.size() == K)
            J[i] = temp.front();
    }
    temp.clear();
    for (int i = 0; i < N; i++)
    {
        if (S[i] == 'O')
            temp.push_back(i);
        if (temp.size() > K)
            temp.pop_front();
        if (temp.size() == K)
            O[i] = temp.front();
    }
    temp.clear();
    for (int i = 0; i < N; i++)
    {
        if (S[i] == 'I')
            temp.push_back(i);
        if (temp.size() > K)
            temp.pop_front();
        if (temp.size() == K)
            I[i] = temp.front();
    }
    int ans = -1;
    for (int i = 0; i < N; i++)
    {
        int u = I[i];
        if (!(u + 1))
            continue;
        int o = O[u];
        if (!(o + 1))
            continue;
        int j = J[o];
        if (!(j + 1))
            continue;
        if (i - j + 1 - (K * 3) > -1)
        {
            ans = min(ans, i - j + 1 - (K * 3));
            if (ans == -1)
                ans = i - j + 1 - (K * 3);
        }
    }
    cout << ans;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:15:25: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   15 |         if (temp.size() > K)
      |             ~~~~~~~~~~~~^~~
ho_t2.cpp:17:25: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   17 |         if (temp.size() == K)
      |             ~~~~~~~~~~~~^~~~
ho_t2.cpp:25:25: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   25 |         if (temp.size() > K)
      |             ~~~~~~~~~~~~^~~
ho_t2.cpp:27:25: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |         if (temp.size() == K)
      |             ~~~~~~~~~~~~^~~~
ho_t2.cpp:35:25: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   35 |         if (temp.size() > K)
      |             ~~~~~~~~~~~~^~~
ho_t2.cpp:37:25: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   37 |         if (temp.size() == K)
      |             ~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 0 ms 296 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 296 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 0 ms 296 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 296 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 300 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 296 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 300 KB Output is correct
25 Correct 1 ms 300 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 300 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 0 ms 296 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 296 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 300 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 296 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 300 KB Output is correct
25 Correct 1 ms 300 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 300 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 8 ms 2916 KB Output is correct
37 Correct 8 ms 3124 KB Output is correct
38 Correct 8 ms 3148 KB Output is correct
39 Correct 8 ms 3044 KB Output is correct
40 Correct 8 ms 3172 KB Output is correct
41 Correct 8 ms 3172 KB Output is correct
42 Correct 8 ms 3144 KB Output is correct
43 Correct 5 ms 2120 KB Output is correct
44 Correct 7 ms 2504 KB Output is correct
45 Correct 8 ms 3172 KB Output is correct
46 Correct 8 ms 3172 KB Output is correct
47 Correct 8 ms 3172 KB Output is correct
48 Correct 8 ms 3172 KB Output is correct
49 Correct 5 ms 2148 KB Output is correct
50 Correct 8 ms 3172 KB Output is correct
51 Correct 8 ms 3140 KB Output is correct
52 Correct 8 ms 3172 KB Output is correct
53 Correct 8 ms 3172 KB Output is correct
54 Correct 6 ms 3172 KB Output is correct
55 Correct 7 ms 3172 KB Output is correct
56 Correct 7 ms 3296 KB Output is correct