Submission #568140

# Submission time Handle Problem Language Result Execution time Memory
568140 2022-05-24T17:04:45 Z Ronin13 JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
13 ms 3648 KB
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;

const int inf = 1e9 + 1;

int main(){
    int n, k; cin >> n >> k;
    string s; cin >> s;
    vector <int> j;
    int ansp[n + 1];
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'O'){
            if(j.size() < k){
                ansp[i] = inf;
            }
            else{
                int x = j[j.size() - 1];
                int y = j[j.size() - k];
                ansp[i] = i - y - k;
            }
        }
        else if(s[i] == 'J')j.pb(i);
    }

    vector <int> i;
    int anss[n + 1];
    for(int p = s.size() - 1; p >= 0; p--){
            if(s[p] == 'O'){
                if(i.size() < k) anss[p] = inf;
                else{
                     int x = i[i.size() - 1];
                     int y = i[i.size() - k];
                     anss[p] = y - p  - k;
                }
            }
            else{if(s[p] == 'I') i.pb(p);}
    }
    vector <int> os;
    for(int p = 0; p < s.size(); p++) if(s[p] == 'O') os.pb(p);
    int ans = inf;
    for(int i = 0; i <= (int)os.size() - k; i++){
        int x = os[i];
        int y = os[i + k - 1];
        ans = min(ans, ansp[x] + anss[y] + y - x + 1 - k);
    }
    if(ans == inf) cout << -1;
    else cout << ans;
    return 0;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:19:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for(int i = 0; i < s.size(); i++){
      |                    ~~^~~~~~~~~~
ho_t2.cpp:21:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   21 |             if(j.size() < k){
      |                ~~~~~~~~~^~~
ho_t2.cpp:25:21: warning: unused variable 'x' [-Wunused-variable]
   25 |                 int x = j[j.size() - 1];
      |                     ^
ho_t2.cpp:37:29: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   37 |                 if(i.size() < k) anss[p] = inf;
      |                    ~~~~~~~~~^~~
ho_t2.cpp:39:26: warning: unused variable 'x' [-Wunused-variable]
   39 |                      int x = i[i.size() - 1];
      |                          ^
ho_t2.cpp:47:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for(int p = 0; p < s.size(); p++) if(s[p] == 'O') os.pb(p);
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 300 KB Output is correct
20 Correct 1 ms 300 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 304 KB Output is correct
23 Correct 1 ms 300 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 296 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 280 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 300 KB Output is correct
20 Correct 1 ms 300 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 304 KB Output is correct
23 Correct 1 ms 300 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 296 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 280 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 10 ms 2912 KB Output is correct
37 Correct 12 ms 3496 KB Output is correct
38 Correct 12 ms 3516 KB Output is correct
39 Correct 11 ms 3420 KB Output is correct
40 Correct 12 ms 3552 KB Output is correct
41 Correct 12 ms 3432 KB Output is correct
42 Correct 13 ms 3556 KB Output is correct
43 Correct 8 ms 2120 KB Output is correct
44 Correct 10 ms 2504 KB Output is correct
45 Correct 12 ms 3520 KB Output is correct
46 Correct 13 ms 3648 KB Output is correct
47 Correct 12 ms 3552 KB Output is correct
48 Correct 11 ms 3524 KB Output is correct
49 Correct 9 ms 2312 KB Output is correct
50 Correct 11 ms 3520 KB Output is correct
51 Correct 11 ms 3552 KB Output is correct
52 Correct 11 ms 3048 KB Output is correct
53 Correct 13 ms 3452 KB Output is correct
54 Correct 8 ms 3548 KB Output is correct
55 Correct 9 ms 3552 KB Output is correct
56 Correct 9 ms 3552 KB Output is correct