Submission #1015373

# Submission time Handle Problem Language Result Execution time Memory
1015373 2024-07-06T09:48:16 Z snpmrnhlol JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
14 ms 4944 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5;
const int inf = 2e9;
char v[N];
vector <int> occ[3];
int nxt[N + 1][3];
int tr[N];
int main(){
    int n,k;
    int ans = inf;
    cin>>n>>k;
    for(int i = 0;i < n;i++){
        cin>>v[i];
        if(v[i] == 'J')v[i] = 0;
        else if(v[i] == 'O')v[i] = 1;
        else v[i] = 2;
        occ[v[i]].push_back(i);
        tr[i] = occ[v[i]].size() - 1;
    }
    nxt[n][0] = nxt[n][1] = nxt[n][2] = n;
    for(int i = n - 1;i >= 0;i--){
        for(int j = 0;j < 3;j++){
            nxt[i][j] = nxt[i + 1][j];
        }
        nxt[i][v[i]] = i;
        //cout<<nxt[i][0]<<' '<<nxt[i][1]<<' '<<nxt[i][2]<<'\n';
    }
    for(int i = 0;i < n;i++){
        int pos = nxt[i][0];
        if(pos == n || occ[0].size() < tr[pos] + k)continue;
        int pos1 = occ[0][tr[pos] + k - 1];
        int id1 = nxt[pos1][1];
        if(id1 == n || occ[1].size() < tr[id1] + k)continue;
        int pos2 = occ[1][tr[id1] + k - 1];
        int id2 = nxt[pos2][2];
        if(id2 == n || occ[2].size() < tr[id2] + k)continue;
        int pos3 = occ[2][tr[id2] + k - 1];
        ///i -> pos3
        ans = min(ans,n - 3*k - (n - 1 - pos3) - (i - 0));
    }
    if(ans == inf)ans = -1;
    cout<<ans<<'\n';
    return 0;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:18:16: warning: array subscript has type 'char' [-Wchar-subscripts]
   18 |         occ[v[i]].push_back(i);
      |             ~~~^
ho_t2.cpp:19:24: warning: array subscript has type 'char' [-Wchar-subscripts]
   19 |         tr[i] = occ[v[i]].size() - 1;
      |                     ~~~^
ho_t2.cpp:26:19: warning: array subscript has type 'char' [-Wchar-subscripts]
   26 |         nxt[i][v[i]] = i;
      |                ~~~^
ho_t2.cpp:31:38: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   31 |         if(pos == n || occ[0].size() < tr[pos] + k)continue;
      |                        ~~~~~~~~~~~~~~^~~~~~~~~~~~~
ho_t2.cpp:34:38: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   34 |         if(id1 == n || occ[1].size() < tr[id1] + k)continue;
      |                        ~~~~~~~~~~~~~~^~~~~~~~~~~~~
ho_t2.cpp:37:38: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   37 |         if(id2 == n || occ[2].size() < tr[id2] + k)continue;
      |                        ~~~~~~~~~~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2392 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2392 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2392 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2492 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2392 KB Output is correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2392 KB Output is correct
34 Correct 1 ms 2500 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2392 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2392 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2492 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2392 KB Output is correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2392 KB Output is correct
34 Correct 1 ms 2500 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 11 ms 4564 KB Output is correct
37 Correct 11 ms 4748 KB Output is correct
38 Correct 11 ms 4776 KB Output is correct
39 Correct 14 ms 4916 KB Output is correct
40 Correct 10 ms 4816 KB Output is correct
41 Correct 12 ms 4752 KB Output is correct
42 Correct 12 ms 4816 KB Output is correct
43 Correct 7 ms 3676 KB Output is correct
44 Correct 8 ms 4056 KB Output is correct
45 Correct 14 ms 4944 KB Output is correct
46 Correct 11 ms 4812 KB Output is correct
47 Correct 10 ms 4816 KB Output is correct
48 Correct 11 ms 4792 KB Output is correct
49 Correct 7 ms 3544 KB Output is correct
50 Correct 13 ms 4816 KB Output is correct
51 Correct 11 ms 4712 KB Output is correct
52 Correct 10 ms 4656 KB Output is correct
53 Correct 14 ms 4864 KB Output is correct
54 Correct 9 ms 4828 KB Output is correct
55 Correct 9 ms 4732 KB Output is correct
56 Correct 8 ms 4828 KB Output is correct