# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
718064 |
2023-04-03T09:24:56 Z |
niter |
JJOOII 2 (JOI20_ho_t2) |
C++14 |
|
12 ms |
3044 KB |
#include <bits/stdc++.h>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define pii pair<int,int>
#define ff first
#define ss second
#define pb push_back
#define ins insert
#define mp make_pair
using namespace std;
void debug(){
cout << "\n";
}
template<class T, class ...U>
void debug(T a, U ...b){
cout << a << " "; debug(b...);
}
const int maxN = 200005;
int main(){
int n, k;
string s;
cin >> n >> k >> s;
deque<int> dqJ, dqO, dqI;
int prevJ[maxN], sufI[maxN];
loop(i,0,n){
prevJ[i] = -1;
sufI[i] = -1;
}
int ans = 2147483647;
// J
loop(i,0,n){
if(dqJ.size() < k){
if(s[i] == 'J'){
dqJ.pb(i);
}
}
else{
prevJ[i] = dqJ.front();
if(s[i] == 'J'){
dqJ.pop_front();
dqJ.pb(i);
}
}
}
// I
for(int i = n-1; i >= 0; i--){
if(dqI.size() < k){
if(s[i] == 'I'){
dqI.push_front(i);
}
}
else{
sufI[i] = dqI.back();
if(s[i] == 'I'){
dqI.pop_back();
dqI.push_front(i);
}
}
}
// O
loop(i,0,n){
if(dqO.size() < k){
if(s[i] == 'O'){
dqO.pb(i);
}
}
else{
if(s[i] == 'O'){
dqO.pop_front();
dqO.pb(i);
}
if(prevJ[dqO.front()] != -1 && sufI[dqO.back()] != -1){
ans = min(ans, sufI[dqO.back()] - prevJ[dqO.front()] + 1 - k * 3);
}
}
}
if(ans == 2147483647){
cout << "-1\n";
return 0;
}
cout << ans << "\n";
return 0;
}
Compilation message
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:34:23: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
34 | if(dqJ.size() < k){
| ~~~~~~~~~~~^~~
ho_t2.cpp:49:23: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
49 | if(dqI.size() < k){
| ~~~~~~~~~~~^~~
ho_t2.cpp:64:23: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
64 | if(dqO.size() < k){
| ~~~~~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1748 KB |
Output is correct |
2 |
Correct |
1 ms |
1748 KB |
Output is correct |
3 |
Correct |
1 ms |
1748 KB |
Output is correct |
4 |
Correct |
1 ms |
1748 KB |
Output is correct |
5 |
Correct |
2 ms |
1748 KB |
Output is correct |
6 |
Correct |
1 ms |
1748 KB |
Output is correct |
7 |
Correct |
1 ms |
1748 KB |
Output is correct |
8 |
Correct |
1 ms |
1748 KB |
Output is correct |
9 |
Correct |
1 ms |
1748 KB |
Output is correct |
10 |
Correct |
1 ms |
1748 KB |
Output is correct |
11 |
Correct |
2 ms |
1748 KB |
Output is correct |
12 |
Correct |
1 ms |
1748 KB |
Output is correct |
13 |
Correct |
1 ms |
1748 KB |
Output is correct |
14 |
Correct |
1 ms |
1748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1748 KB |
Output is correct |
2 |
Correct |
1 ms |
1748 KB |
Output is correct |
3 |
Correct |
1 ms |
1748 KB |
Output is correct |
4 |
Correct |
1 ms |
1748 KB |
Output is correct |
5 |
Correct |
2 ms |
1748 KB |
Output is correct |
6 |
Correct |
1 ms |
1748 KB |
Output is correct |
7 |
Correct |
1 ms |
1748 KB |
Output is correct |
8 |
Correct |
1 ms |
1748 KB |
Output is correct |
9 |
Correct |
1 ms |
1748 KB |
Output is correct |
10 |
Correct |
1 ms |
1748 KB |
Output is correct |
11 |
Correct |
2 ms |
1748 KB |
Output is correct |
12 |
Correct |
1 ms |
1748 KB |
Output is correct |
13 |
Correct |
1 ms |
1748 KB |
Output is correct |
14 |
Correct |
1 ms |
1748 KB |
Output is correct |
15 |
Correct |
2 ms |
1876 KB |
Output is correct |
16 |
Correct |
1 ms |
1748 KB |
Output is correct |
17 |
Correct |
1 ms |
1748 KB |
Output is correct |
18 |
Correct |
1 ms |
1876 KB |
Output is correct |
19 |
Correct |
1 ms |
1748 KB |
Output is correct |
20 |
Correct |
1 ms |
1876 KB |
Output is correct |
21 |
Correct |
1 ms |
1856 KB |
Output is correct |
22 |
Correct |
1 ms |
1876 KB |
Output is correct |
23 |
Correct |
1 ms |
1864 KB |
Output is correct |
24 |
Correct |
2 ms |
1868 KB |
Output is correct |
25 |
Correct |
1 ms |
1876 KB |
Output is correct |
26 |
Correct |
1 ms |
1860 KB |
Output is correct |
27 |
Correct |
1 ms |
1876 KB |
Output is correct |
28 |
Correct |
1 ms |
1860 KB |
Output is correct |
29 |
Correct |
1 ms |
1864 KB |
Output is correct |
30 |
Correct |
2 ms |
1876 KB |
Output is correct |
31 |
Correct |
1 ms |
1856 KB |
Output is correct |
32 |
Correct |
2 ms |
1864 KB |
Output is correct |
33 |
Correct |
2 ms |
1860 KB |
Output is correct |
34 |
Correct |
2 ms |
1748 KB |
Output is correct |
35 |
Correct |
1 ms |
1860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1748 KB |
Output is correct |
2 |
Correct |
1 ms |
1748 KB |
Output is correct |
3 |
Correct |
1 ms |
1748 KB |
Output is correct |
4 |
Correct |
1 ms |
1748 KB |
Output is correct |
5 |
Correct |
2 ms |
1748 KB |
Output is correct |
6 |
Correct |
1 ms |
1748 KB |
Output is correct |
7 |
Correct |
1 ms |
1748 KB |
Output is correct |
8 |
Correct |
1 ms |
1748 KB |
Output is correct |
9 |
Correct |
1 ms |
1748 KB |
Output is correct |
10 |
Correct |
1 ms |
1748 KB |
Output is correct |
11 |
Correct |
2 ms |
1748 KB |
Output is correct |
12 |
Correct |
1 ms |
1748 KB |
Output is correct |
13 |
Correct |
1 ms |
1748 KB |
Output is correct |
14 |
Correct |
1 ms |
1748 KB |
Output is correct |
15 |
Correct |
2 ms |
1876 KB |
Output is correct |
16 |
Correct |
1 ms |
1748 KB |
Output is correct |
17 |
Correct |
1 ms |
1748 KB |
Output is correct |
18 |
Correct |
1 ms |
1876 KB |
Output is correct |
19 |
Correct |
1 ms |
1748 KB |
Output is correct |
20 |
Correct |
1 ms |
1876 KB |
Output is correct |
21 |
Correct |
1 ms |
1856 KB |
Output is correct |
22 |
Correct |
1 ms |
1876 KB |
Output is correct |
23 |
Correct |
1 ms |
1864 KB |
Output is correct |
24 |
Correct |
2 ms |
1868 KB |
Output is correct |
25 |
Correct |
1 ms |
1876 KB |
Output is correct |
26 |
Correct |
1 ms |
1860 KB |
Output is correct |
27 |
Correct |
1 ms |
1876 KB |
Output is correct |
28 |
Correct |
1 ms |
1860 KB |
Output is correct |
29 |
Correct |
1 ms |
1864 KB |
Output is correct |
30 |
Correct |
2 ms |
1876 KB |
Output is correct |
31 |
Correct |
1 ms |
1856 KB |
Output is correct |
32 |
Correct |
2 ms |
1864 KB |
Output is correct |
33 |
Correct |
2 ms |
1860 KB |
Output is correct |
34 |
Correct |
2 ms |
1748 KB |
Output is correct |
35 |
Correct |
1 ms |
1860 KB |
Output is correct |
36 |
Correct |
10 ms |
2400 KB |
Output is correct |
37 |
Correct |
10 ms |
2388 KB |
Output is correct |
38 |
Correct |
11 ms |
2420 KB |
Output is correct |
39 |
Correct |
10 ms |
2320 KB |
Output is correct |
40 |
Correct |
10 ms |
2404 KB |
Output is correct |
41 |
Correct |
11 ms |
2388 KB |
Output is correct |
42 |
Correct |
10 ms |
2384 KB |
Output is correct |
43 |
Correct |
6 ms |
2276 KB |
Output is correct |
44 |
Correct |
10 ms |
2268 KB |
Output is correct |
45 |
Correct |
10 ms |
2532 KB |
Output is correct |
46 |
Correct |
12 ms |
2528 KB |
Output is correct |
47 |
Correct |
11 ms |
2452 KB |
Output is correct |
48 |
Correct |
11 ms |
2524 KB |
Output is correct |
49 |
Correct |
7 ms |
2272 KB |
Output is correct |
50 |
Correct |
10 ms |
2424 KB |
Output is correct |
51 |
Correct |
10 ms |
2556 KB |
Output is correct |
52 |
Correct |
10 ms |
2916 KB |
Output is correct |
53 |
Correct |
11 ms |
2916 KB |
Output is correct |
54 |
Correct |
8 ms |
2388 KB |
Output is correct |
55 |
Correct |
10 ms |
2788 KB |
Output is correct |
56 |
Correct |
8 ms |
3044 KB |
Output is correct |