# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
535304 |
2022-03-10T01:43:20 Z |
Biaz |
JJOOII 2 (JOI20_ho_t2) |
C++17 |
|
2000 ms |
2012 KB |
#include<bits/stdc++.h>
//#define int long long
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define fi first
#define se second
#define ist insert
using namespace std;
int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a>b?a:b;}
typedef long long ll;
typedef pair<ll,ll> pii;
const int N=200005;
const int MOD=1000000007;//998244353
const int INF=2147483647;//1700000000000000000
int n,k;
string s;
vector<int> site[3];
int a[N];
vector<pii> dp[3];
bool vaild(){
int cnt=0,typ=0;
for (int i=0;i<n;i++){
if (typ==0&&s[i]=='J') cnt++;
if (typ==1&&s[i]=='O') cnt++;
if (typ==2&&s[i]=='I') cnt++;
if (cnt==k) cnt=0,typ++;
}
return typ==3;
}
int srch1(int x){
int l=0,r=dp[0].size(),res=-1;
while (r>=l){
int mid=(l+r)/2;
if (dp[0][mid].fi<x){
res=mid;
l=mid+1;
}
else r=mid-1;
}
return res;
}
int srch2(int x){
int l=0,r=dp[2].size(),res=-1;
while (r>=l){
int mid=(l+r)/2;
if (dp[2][mid].fi>x){
res=mid;
r=mid-1;
}
else l=mid+1;
}
return res;
}
inline void sol(){
cin >>n>>k>>s;
if (!vaild()){
cout <<"-1\n";
return;
}
for (int i=0;i<n;i++){
if (s[i]=='J') a[i]=0;
if (s[i]=='O') a[i]=1;
if (s[i]=='I') a[i]=2;
site[a[i]].pb(i);
}
int ans=INF;
for (int t=k-1;t<site[0].size();t++){
int i=t-k+1;
for (int j=k-1;j<site[2].size();j++){
if ((lower_bound(ALL(site[1]),site[2][j-k+1])-lower_bound(ALL(site[1]),site[0][t]))<k||site[0][i]>site[2][j]) continue;
//cout <<site[2][j]<<' '<<site[0][i]<<'\n';
ans=min(ans,site[2][j]-site[0][i]+1-(k*3));
}
}
cout <<ans<<'\n';
}
signed main(){
int _=1;
//cin >>_;
while (_--) sol();
return 0;
}
Compilation message
ho_t2.cpp: In function 'void sol()':
ho_t2.cpp:70:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for (int t=k-1;t<site[0].size();t++){
| ~^~~~~~~~~~~~~~~
ho_t2.cpp:72:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for (int j=k-1;j<site[2].size();j++){
| ~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 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 |
29 ms |
320 KB |
Output is correct |
16 |
Correct |
41 ms |
320 KB |
Output is correct |
17 |
Correct |
37 ms |
340 KB |
Output is correct |
18 |
Correct |
10 ms |
344 KB |
Output is correct |
19 |
Correct |
44 ms |
348 KB |
Output is correct |
20 |
Correct |
40 ms |
340 KB |
Output is correct |
21 |
Correct |
29 ms |
340 KB |
Output is correct |
22 |
Correct |
14 ms |
344 KB |
Output is correct |
23 |
Correct |
5 ms |
212 KB |
Output is correct |
24 |
Correct |
18 ms |
340 KB |
Output is correct |
25 |
Correct |
16 ms |
340 KB |
Output is correct |
26 |
Correct |
16 ms |
340 KB |
Output is correct |
27 |
Correct |
19 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
19 ms |
340 KB |
Output is correct |
34 |
Correct |
9 ms |
340 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 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 |
29 ms |
320 KB |
Output is correct |
16 |
Correct |
41 ms |
320 KB |
Output is correct |
17 |
Correct |
37 ms |
340 KB |
Output is correct |
18 |
Correct |
10 ms |
344 KB |
Output is correct |
19 |
Correct |
44 ms |
348 KB |
Output is correct |
20 |
Correct |
40 ms |
340 KB |
Output is correct |
21 |
Correct |
29 ms |
340 KB |
Output is correct |
22 |
Correct |
14 ms |
344 KB |
Output is correct |
23 |
Correct |
5 ms |
212 KB |
Output is correct |
24 |
Correct |
18 ms |
340 KB |
Output is correct |
25 |
Correct |
16 ms |
340 KB |
Output is correct |
26 |
Correct |
16 ms |
340 KB |
Output is correct |
27 |
Correct |
19 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
19 ms |
340 KB |
Output is correct |
34 |
Correct |
9 ms |
340 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
36 |
Execution timed out |
2068 ms |
2012 KB |
Time limit exceeded |
37 |
Halted |
0 ms |
0 KB |
- |