Submission #540935

# Submission time Handle Problem Language Result Execution time Memory
540935 2022-03-22T02:57:40 Z Fysty JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
11 ms 3160 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> void _do(T x){cerr<<x<<"\n";}
template<typename T,typename ...U> void _do(T x,U ...y){cerr<<x<<", ";_do(y...);}
#define dbg(...) cerr<<#__VA_ARGS__<<" = ";_do(__VA_ARGS__);
const ll INF=3e18;
#define MottoHayaku ios::sync_with_stdio(false);cin.tie(0);
//#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define F first
#define S second
#define pb push_back

ll n,k;
string s;
vector<ll> pos[3];

signed main()
{
    MottoHayaku
    cin>>n>>k>>s;
    rep(i,n)
    {
        if(s[i]=='J') pos[0].pb(i);
        else if(s[i]=='O') pos[1].pb(i);
        else pos[2].pb(i);
    }
    ll ans=INF;
    rep(i,(ll)pos[0].size()-k+1)
    {
        ll cur=pos[0][i+k-1];
        ll tmp=lower_bound(pos[1].begin(),pos[1].end(),cur)-pos[1].begin();
        if(tmp+k-1>=pos[1].size()) break;
        cur=pos[1][tmp+k-1];
        tmp=lower_bound(pos[2].begin(),pos[2].end(),cur)-pos[2].begin();
        if(tmp+k-1>=pos[2].size()) break;
        ans=min(ans,pos[2][tmp+k-1]-pos[0][i]+1-3*k);
    }
    if(ans==INF) cout<<"-1\n";
    else cout<<ans<<"\n";
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:37:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         if(tmp+k-1>=pos[1].size()) break;
      |            ~~~~~~~^~~~~~~~~~~~~~~
ho_t2.cpp:40:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         if(tmp+k-1>=pos[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 316 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 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 320 KB Output is correct
11 Correct 1 ms 316 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 324 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 316 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 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 320 KB Output is correct
11 Correct 1 ms 316 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 324 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 316 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 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 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 316 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 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 320 KB Output is correct
11 Correct 1 ms 316 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 324 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 316 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 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 316 KB Output is correct
36 Correct 9 ms 2184 KB Output is correct
37 Correct 11 ms 2696 KB Output is correct
38 Correct 10 ms 2740 KB Output is correct
39 Correct 9 ms 2836 KB Output is correct
40 Correct 5 ms 2884 KB Output is correct
41 Correct 8 ms 2892 KB Output is correct
42 Correct 10 ms 2728 KB Output is correct
43 Correct 3 ms 1704 KB Output is correct
44 Correct 3 ms 2000 KB Output is correct
45 Correct 4 ms 2832 KB Output is correct
46 Correct 4 ms 2832 KB Output is correct
47 Correct 5 ms 2884 KB Output is correct
48 Correct 6 ms 2796 KB Output is correct
49 Correct 3 ms 1740 KB Output is correct
50 Correct 5 ms 2796 KB Output is correct
51 Correct 5 ms 2912 KB Output is correct
52 Correct 3 ms 2232 KB Output is correct
53 Correct 4 ms 2760 KB Output is correct
54 Correct 7 ms 3160 KB Output is correct
55 Correct 4 ms 3160 KB Output is correct
56 Correct 3 ms 3148 KB Output is correct