Submission #647311

# Submission time Handle Problem Language Result Execution time Memory
647311 2022-10-02T07:34:00 Z ck_platypus JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
9 ms 3120 KB
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <utility>
#include <bitset>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <queue>
#include <cstring>
#include <fstream>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pll pair<ll, ll>
#define plpll pair<ll, pll>
#define pii pair<int, int>
#define f first
#define s second
#define inf 1000000000000000
#define endl '\n'
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n, k;
    cin >> n >> k;
    vector<ll> a[3];
    char in;
    for(int i=0;i<n;i++){
        cin >> in;
        if(in=='J') a[0].pb(i);
        else if(in=='O') a[1].pb(i);
        else a[2].pb(i);
    }
    if(a[0].size()<k){
        cout << "-1\n";
        return 0;
    }
    ll ol=0, il=0, ans=-1;
    for(int i=k-1;i<a[0].size();i++){
        while(a[1][ol]<a[0][i] && ol<a[1].size()) ol++;
        if(ol+k>a[1].size()) break;
        while(a[2][il]<a[1][ol+k-1]) il++;
        if(il+k>a[2].size()) break;
        //cout << i << " " << ol << " " << il << endl;
        if(ans==-1 || ans>a[2][il+k-1]-a[0][i-k+1]-k*3+1) ans=a[2][il+k-1]-a[0][i-k+1]-k*3+1;
    }
    cout << ans << endl;
    return 0;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:38:19: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   38 |     if(a[0].size()<k){
      |        ~~~~~~~~~~~^~
ho_t2.cpp:43:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for(int i=k-1;i<a[0].size();i++){
      |                   ~^~~~~~~~~~~~
ho_t2.cpp:44:37: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         while(a[1][ol]<a[0][i] && ol<a[1].size()) ol++;
      |                                   ~~^~~~~~~~~~~~
ho_t2.cpp:45:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |         if(ol+k>a[1].size()) break;
      |            ~~~~^~~~~~~~~~~~
ho_t2.cpp:47:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         if(il+k>a[2].size()) break;
      |            ~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 1 ms 316 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 212 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 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 1 ms 316 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 212 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 316 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 276 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 340 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 320 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 340 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 1 ms 212 KB Output is correct
2 Correct 1 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 1 ms 316 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 212 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 316 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 276 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 340 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 320 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 340 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 Correct 8 ms 2116 KB Output is correct
37 Correct 9 ms 2628 KB Output is correct
38 Correct 9 ms 2724 KB Output is correct
39 Correct 8 ms 2636 KB Output is correct
40 Correct 8 ms 2632 KB Output is correct
41 Correct 8 ms 2856 KB Output is correct
42 Correct 8 ms 2628 KB Output is correct
43 Correct 5 ms 1804 KB Output is correct
44 Correct 6 ms 1756 KB Output is correct
45 Correct 7 ms 2632 KB Output is correct
46 Correct 7 ms 2632 KB Output is correct
47 Correct 8 ms 2700 KB Output is correct
48 Correct 7 ms 2632 KB Output is correct
49 Correct 5 ms 1620 KB Output is correct
50 Correct 8 ms 2712 KB Output is correct
51 Correct 8 ms 2624 KB Output is correct
52 Correct 8 ms 2120 KB Output is correct
53 Correct 7 ms 2888 KB Output is correct
54 Correct 5 ms 3120 KB Output is correct
55 Correct 5 ms 3028 KB Output is correct
56 Correct 7 ms 3028 KB Output is correct