# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
212142 | 2020-03-22T10:46:37 Z | kshitij_sodani | JJOOII 2 (JOI20_ho_t2) | C++17 | 38 ms | 9984 KB |
#include <iostream> #include <bits/stdc++.h> using namespace std; typedef long long llo; #define mp make_pair #define pb push_back #define a first #define b second int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n,k; cin>>n>>k; char ss; int it[n]; for(int i=0;i<n;i++){ cin>>ss; if(ss=='O'){ it[i]=1; } else if(ss=='I'){ it[i]=2; } else{ it[i]=0; } } int pre[n]; pre[0]=0; if(it[0]==1){ pre[0]=1; } for(int i=1;i<n;i++){ pre[i]=pre[i-1]; pre[i]+=it[i]%2; } multiset<int> aa; multiset<int,greater<int>> bb; int dp[n]; int dp2[n]; for(int i=0;i<n;i++){ dp[i]=n+1; dp2[i]=n+1; } for(int i=0;i<n;i++){ if(it[i]==0){ aa.insert(i); if(aa.size()>k){ auto ac=aa.begin(); aa.erase(ac); } if(aa.size()==k){ dp[i]=(i-(*aa.begin())+1-k); } } if(i>0){ dp[i]=min(dp[i],dp[i-1]+1); } } for(int i=n-1;i>=0;i--){ if(it[i]==2){ bb.insert(i); if(bb.size()>k){ auto ac=bb.begin(); bb.erase(ac); } if(bb.size()==k){ dp2[i]=((*bb.begin())-i+1-k); } } if(i<n-1){ dp2[i]=min(dp2[i],dp2[i+1]+1); } } int mi=n+1; int ind=0; int ans=n+1; /*for(int i=0;i<n;i++){ cout<<dp[i]<<" "; } cout<<endl;*/ /* muliset<int> ak; multiset<int> bk; */ for(int i=2;i<n;i++){ mi+=1; while(ind<i-1){ if(pre[i-1]-pre[ind]>=k){ mi=min(mi,dp[ind]+(i-1-ind-k)); ind+=1; } else{ break; } } ans=min(ans,mi+dp2[i]); } if(ans<=n){ cout<<ans<<endl; } else{ cout<<-1<<endl; } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Correct | 4 ms | 384 KB | Output is correct |
3 | Correct | 4 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 384 KB | Output is correct |
7 | Correct | 5 ms | 384 KB | Output is correct |
8 | Correct | 5 ms | 384 KB | Output is correct |
9 | Correct | 5 ms | 384 KB | Output is correct |
10 | Correct | 5 ms | 384 KB | Output is correct |
11 | Correct | 4 ms | 384 KB | Output is correct |
12 | Correct | 5 ms | 384 KB | Output is correct |
13 | Correct | 4 ms | 384 KB | Output is correct |
14 | Correct | 5 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Correct | 4 ms | 384 KB | Output is correct |
3 | Correct | 4 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 384 KB | Output is correct |
7 | Correct | 5 ms | 384 KB | Output is correct |
8 | Correct | 5 ms | 384 KB | Output is correct |
9 | Correct | 5 ms | 384 KB | Output is correct |
10 | Correct | 5 ms | 384 KB | Output is correct |
11 | Correct | 4 ms | 384 KB | Output is correct |
12 | Correct | 5 ms | 384 KB | Output is correct |
13 | Correct | 4 ms | 384 KB | Output is correct |
14 | Correct | 5 ms | 384 KB | Output is correct |
15 | Correct | 5 ms | 384 KB | Output is correct |
16 | Correct | 5 ms | 384 KB | Output is correct |
17 | Correct | 5 ms | 384 KB | Output is correct |
18 | Correct | 5 ms | 384 KB | Output is correct |
19 | Correct | 5 ms | 384 KB | Output is correct |
20 | Correct | 5 ms | 384 KB | Output is correct |
21 | Correct | 5 ms | 384 KB | Output is correct |
22 | Correct | 5 ms | 384 KB | Output is correct |
23 | Correct | 5 ms | 384 KB | Output is correct |
24 | Correct | 5 ms | 384 KB | Output is correct |
25 | Correct | 5 ms | 384 KB | Output is correct |
26 | Correct | 5 ms | 384 KB | Output is correct |
27 | Correct | 5 ms | 384 KB | Output is correct |
28 | Correct | 5 ms | 384 KB | Output is correct |
29 | Correct | 5 ms | 384 KB | Output is correct |
30 | Correct | 5 ms | 384 KB | Output is correct |
31 | Correct | 10 ms | 384 KB | Output is correct |
32 | Correct | 5 ms | 384 KB | Output is correct |
33 | Correct | 5 ms | 384 KB | Output is correct |
34 | Correct | 5 ms | 384 KB | Output is correct |
35 | Correct | 5 ms | 512 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Correct | 4 ms | 384 KB | Output is correct |
3 | Correct | 4 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 384 KB | Output is correct |
7 | Correct | 5 ms | 384 KB | Output is correct |
8 | Correct | 5 ms | 384 KB | Output is correct |
9 | Correct | 5 ms | 384 KB | Output is correct |
10 | Correct | 5 ms | 384 KB | Output is correct |
11 | Correct | 4 ms | 384 KB | Output is correct |
12 | Correct | 5 ms | 384 KB | Output is correct |
13 | Correct | 4 ms | 384 KB | Output is correct |
14 | Correct | 5 ms | 384 KB | Output is correct |
15 | Correct | 5 ms | 384 KB | Output is correct |
16 | Correct | 5 ms | 384 KB | Output is correct |
17 | Correct | 5 ms | 384 KB | Output is correct |
18 | Correct | 5 ms | 384 KB | Output is correct |
19 | Correct | 5 ms | 384 KB | Output is correct |
20 | Correct | 5 ms | 384 KB | Output is correct |
21 | Correct | 5 ms | 384 KB | Output is correct |
22 | Correct | 5 ms | 384 KB | Output is correct |
23 | Correct | 5 ms | 384 KB | Output is correct |
24 | Correct | 5 ms | 384 KB | Output is correct |
25 | Correct | 5 ms | 384 KB | Output is correct |
26 | Correct | 5 ms | 384 KB | Output is correct |
27 | Correct | 5 ms | 384 KB | Output is correct |
28 | Correct | 5 ms | 384 KB | Output is correct |
29 | Correct | 5 ms | 384 KB | Output is correct |
30 | Correct | 5 ms | 384 KB | Output is correct |
31 | Correct | 10 ms | 384 KB | Output is correct |
32 | Correct | 5 ms | 384 KB | Output is correct |
33 | Correct | 5 ms | 384 KB | Output is correct |
34 | Correct | 5 ms | 384 KB | Output is correct |
35 | Correct | 5 ms | 512 KB | Output is correct |
36 | Correct | 20 ms | 3456 KB | Output is correct |
37 | Correct | 22 ms | 3712 KB | Output is correct |
38 | Correct | 23 ms | 3712 KB | Output is correct |
39 | Correct | 31 ms | 4088 KB | Output is correct |
40 | Correct | 36 ms | 5376 KB | Output is correct |
41 | Correct | 34 ms | 4480 KB | Output is correct |
42 | Correct | 30 ms | 3840 KB | Output is correct |
43 | Correct | 23 ms | 3712 KB | Output is correct |
44 | Correct | 29 ms | 4480 KB | Output is correct |
45 | Correct | 36 ms | 5760 KB | Output is correct |
46 | Correct | 37 ms | 5760 KB | Output is correct |
47 | Correct | 37 ms | 5788 KB | Output is correct |
48 | Correct | 37 ms | 5788 KB | Output is correct |
49 | Correct | 26 ms | 3968 KB | Output is correct |
50 | Correct | 36 ms | 5752 KB | Output is correct |
51 | Correct | 37 ms | 5760 KB | Output is correct |
52 | Correct | 36 ms | 8696 KB | Output is correct |
53 | Correct | 37 ms | 8824 KB | Output is correct |
54 | Correct | 17 ms | 3712 KB | Output is correct |
55 | Correct | 38 ms | 7808 KB | Output is correct |
56 | Correct | 36 ms | 9984 KB | Output is correct |