# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
933682 |
2024-02-26T05:15:29 Z |
ByeWorld |
JJOOII 2 (JOI20_ho_t2) |
C++14 |
|
13 ms |
6776 KB |
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define int long long
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
using namespace std;
typedef pair<int,int> pii;
typedef pair<string, pii> ipii;
const int INF = 1e9+10;
const int MAXN = 1e6+10;
int n, k;
int O[MAXN], I[MAXN];
string s;
int mn = INF;
vector <int> vec;
void f(int idx, int fr){
int l=idx, r=n, cnt=-1, mid=0;
while(l<=r){
mid = md;
if(O[idx]-O[mid+1] >= k){ // ke kiri
r = mid-1; cnt = mid;
} else l = mid+1;
}
int ido = cnt;
if(ido == -1) return;
//cout << ido << " O\n";
l = cnt, r=n, cnt=-1, mid=0;
while(l<=r){
mid = md;
if(I[ido]-I[mid+1] >= k){
r = mid-1; cnt = mid;
} else l = mid+1;
}
if(cnt == -1) return;
//cout << cnt << " i\n";
mn = min(mn, cnt-fr+1 - 3*k);
}
signed main(){
cin >> n >> k;
cin >> s; s = '.'+s;
for(int i=n; i>=1; i--){
O[i] = O[i+1] + (s[i]=='O' ? 1 : 0);
I[i] = I[i+1] + (s[i]=='I' ? 1 : 0);
}
for(int i=1; i<=n; i++){
if(s[i] == 'J'){
vec.pb(i);
}
}
for(int i=k-1; i<vec.size(); i++){
f(vec[i], vec[i-k+1]);
}
cout << (mn>n ? -1 : mn) << '\n';
}
Compilation message
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:56:18: 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]
56 | for(int i=k-1; i<vec.size(); i++){
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
444 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
452 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
444 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
452 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
448 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
444 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
452 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
448 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
12 ms |
5940 KB |
Output is correct |
37 |
Correct |
10 ms |
6692 KB |
Output is correct |
38 |
Correct |
13 ms |
6776 KB |
Output is correct |
39 |
Correct |
11 ms |
6692 KB |
Output is correct |
40 |
Correct |
9 ms |
6604 KB |
Output is correct |
41 |
Correct |
10 ms |
6692 KB |
Output is correct |
42 |
Correct |
12 ms |
6692 KB |
Output is correct |
43 |
Correct |
5 ms |
4720 KB |
Output is correct |
44 |
Correct |
6 ms |
5204 KB |
Output is correct |
45 |
Correct |
8 ms |
6692 KB |
Output is correct |
46 |
Correct |
8 ms |
6600 KB |
Output is correct |
47 |
Correct |
8 ms |
6692 KB |
Output is correct |
48 |
Correct |
8 ms |
6616 KB |
Output is correct |
49 |
Correct |
5 ms |
4968 KB |
Output is correct |
50 |
Correct |
8 ms |
6692 KB |
Output is correct |
51 |
Correct |
10 ms |
6692 KB |
Output is correct |
52 |
Correct |
6 ms |
5936 KB |
Output is correct |
53 |
Correct |
6 ms |
6520 KB |
Output is correct |
54 |
Correct |
10 ms |
6692 KB |
Output is correct |
55 |
Correct |
7 ms |
6692 KB |
Output is correct |
56 |
Correct |
6 ms |
6692 KB |
Output is correct |