Submission #747683

# Submission time Handle Problem Language Result Execution time Memory
747683 2023-05-24T13:19:33 Z Sami_Massah JJOOII 2 (JOI20_ho_t2) C++17
13 / 100
6 ms 1300 KB
#include <bits/stdc++.h>
using namespace std;


const long long maxn = 3e3 + 12, mod = 1e9 + 7, inf = 1e9 + 12 ;
long long n, k, cnt[maxn];
vector<int> locs[3];
string s;
int main(){
    cin >> n >> k;
    cin >> s;
    cnt[1] = (s[0] == 'O');
    for(int i = 1; i < n; i++)
        if(s[i] == 'O')
            cnt[i] = cnt[i - 1] + 1;
        else
            cnt[i] = cnt[i - 1];
    for(int i = 0; i < n; i++)
        if(s[i] == 'J')
            locs[0].push_back(i);
        else if(s[i] == 'O')
            locs[1].push_back(i);
        else
            locs[2].push_back(i);
    long long ans = maxn;
    for(int loc = 0; loc + k - 1 < locs[0].size(); loc++){
        int ne = locs[0][loc + k - 1];
        int l = -1, r = locs[2].size() - k + 1, mid;
        while(r - l != 1){
            int mid = (l + r) / 2;
            if(cnt[locs[2][mid]] - cnt[ne] >= k)
                r = mid;
            else
                l = mid;


        }
        if(r != locs[2].size() - k + 1)
            ans = min(ans, locs[2][r + k - 1] - locs[0][loc] + 1 - k * 3);

    }
    if(ans == maxn)
        ans = -1;
    cout << ans << endl;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:26:34: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for(int loc = 0; loc + k - 1 < locs[0].size(); loc++){
      |                      ~~~~~~~~~~~~^~~~~~~~~~~~~~~~
ho_t2.cpp:38:14: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
   38 |         if(r != locs[2].size() - k + 1)
      |            ~~^~~~~~~~~~~~~~~~~~~~~~~~~
ho_t2.cpp:28:49: warning: unused variable 'mid' [-Wunused-variable]
   28 |         int l = -1, r = locs[2].size() - k + 1, mid;
      |                                                 ^~~
# 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 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 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 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 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 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 212 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 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 304 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 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 340 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 300 KB Output is correct
33 Correct 1 ms 340 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 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 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 212 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 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 304 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 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 340 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 300 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Runtime error 6 ms 1300 KB Execution killed with signal 11
37 Halted 0 ms 0 KB -