Submission #286668

# Submission time Handle Problem Language Result Execution time Memory
286668 2020-08-30T17:03:20 Z leductoan JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
30 ms 4808 KB
#include<bits/stdc++.h>
using namespace std;
#define task "JOI20_ho_t2"
#define lb lower_bound
#define ub upper_bound
#define ALL(v) (v).begin(),(v).end()
#define zs(v) (int)(v).size()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define cntbit __builtin_popcountll
typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};
const ll mod=1000000007; /// 998244353
const int base=311;
const int N=2e5+5;

int n,k,f[N][5];
string s;

void biot()
{
    cin>>n>>k;
    cin>>s;
    s=' '+s;
    int l=1;
    string t="JOI";
    for(int i=1;i<=n;++i)
    {
        for(int j=0;j<3;++j)
        {
            f[i][j]=f[i-1][j]+(s[i]==t[j]);
        }
    }
    int ans=1e9;
    for(int i=1;i<=n;++i)
    {
        int l=i, r=n, j=-1, o=-1, ii=-1;
        while(l<=r)
        {
            int mid=(l+r)>>1;
            if(f[mid][0]-f[i-1][0]>=k) r=mid-1, j=mid;
            else l=mid+1;
        }
        if(j==-1) continue;
        l=j+1, r=n;
        while(l<=r)
        {
            int mid=(l+r)>>1;
            if(f[mid][1]-f[j][1]>=k) r=mid-1, o=mid;
            else l=mid+1;
        }
        if(o==-1) continue;
        l=o+1, r=n;
        while(l<=r)
        {
            int mid=(l+r)>>1;
            if(f[mid][2]-f[o][2]>=k) r=mid-1, ii=mid;
            else l=mid+1;
        }
        if(ii!=-1) ans=min(ans,ii-i+1-k*3);
    }
    cout<<(ans==1e9?-1:ans);
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    if(fopen(task".inp","r"))
    {
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    biot();
}











Compilation message

ho_t2.cpp: In function 'void biot()':
ho_t2.cpp:30:9: warning: unused variable 'l' [-Wunused-variable]
   30 |     int l=1;
      |         ^
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   74 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
ho_t2.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   75 |         freopen(task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 512 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 512 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 512 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 23 ms 4308 KB Output is correct
37 Correct 26 ms 4784 KB Output is correct
38 Correct 25 ms 4808 KB Output is correct
39 Correct 28 ms 4680 KB Output is correct
40 Correct 22 ms 4696 KB Output is correct
41 Correct 27 ms 4808 KB Output is correct
42 Correct 30 ms 4808 KB Output is correct
43 Correct 11 ms 3200 KB Output is correct
44 Correct 14 ms 3828 KB Output is correct
45 Correct 18 ms 4808 KB Output is correct
46 Correct 19 ms 4808 KB Output is correct
47 Correct 18 ms 4808 KB Output is correct
48 Correct 20 ms 4808 KB Output is correct
49 Correct 12 ms 3336 KB Output is correct
50 Correct 18 ms 4808 KB Output is correct
51 Correct 18 ms 4808 KB Output is correct
52 Correct 9 ms 4560 KB Output is correct
53 Correct 10 ms 4808 KB Output is correct
54 Correct 15 ms 4808 KB Output is correct
55 Correct 11 ms 4808 KB Output is correct
56 Correct 8 ms 4808 KB Output is correct