# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
753938 |
2023-06-06T10:59:44 Z |
vjudge1 |
JJOOII 2 (JOI20_ho_t2) |
C++17 |
|
7 ms |
2760 KB |
#include <bits/stdc++.h>
#define Kuanyshh ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;
//#define s second
//#define f first
#pragma GCC optimize( "Ofast", "O3" , "unroll-loops")
#pragma GCC target ("sse,sse2")
using namespace std;
using ll = long long;
const int inf = 1e18+77;
const int mod = 1e9+7;
const int mx = 1e5+79;
int cntj[mx], cnto[mx], cnti[mx];
void shift(){
int n, k;
string s;
cin >> n >> k >> s;
int res = inf, index, kj = 0, ko = 0, ki = 0, ko2=0, ki2=0;
vector<int> o, ii, j;
for(int i = 0; i < s.size(); i++){
if(s[i] == 'J'){
j.push_back(i);
cntj[j.size()] = i;
}
if(s[i] == 'O'){
o.push_back(i);
cnto[o.size()] = i;
}
if(s[i] == 'I'){
ii.push_back(i);
cnti[ii.size()] = i;
}
}
kj = j.size();
ko = o.size();
ki = ii.size();
for(int i = 1; i <= kj; i++){
if(i + k - 1 > kj){
break;
}else{
index = cntj[i + k - 1];
}
while(cnto[ko2] <= index){
ko2++;
if(ko2 > ko) break;
}
if(ko2 + k - 1 > ko){
break;
}else{
index = cnto[ko2 + k - 1];
}
while(cnti[ki2] < index){
ki2++;
if(ki2 > ki){
break;
}
}
if(ki2 + k - 1 > ki){
break;
}else{
index = cnti[ki2 + k - 1];
}
int ans = index - cntj[i] + 1 - 3 * k;
res = min(res, ans);
}
if(res == inf || res < 0) cout << -1;
else cout << res;
}
signed main(){
Kuanyshh;
int tt = 1;
// // cin >> tt;
while(tt--){
shift();
}
}
Compilation message
ho_t2.cpp:12:21: warning: overflow in conversion from 'double' to 'int' changes value from '1.0000000000000001e+18' to '2147483647' [-Woverflow]
12 | const int inf = 1e18+77;
| ~~~~^~~
ho_t2.cpp: In function 'void shift()':
ho_t2.cpp:24:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for(int i = 0; i < s.size(); i++){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
412 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
328 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
412 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
328 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
6 ms |
2256 KB |
Output is correct |
37 |
Correct |
7 ms |
2592 KB |
Output is correct |
38 |
Correct |
6 ms |
2696 KB |
Output is correct |
39 |
Correct |
6 ms |
2664 KB |
Output is correct |
40 |
Correct |
7 ms |
2648 KB |
Output is correct |
41 |
Correct |
6 ms |
2760 KB |
Output is correct |
42 |
Correct |
6 ms |
2560 KB |
Output is correct |
43 |
Correct |
3 ms |
1772 KB |
Output is correct |
44 |
Correct |
4 ms |
2008 KB |
Output is correct |
45 |
Correct |
5 ms |
2736 KB |
Output is correct |
46 |
Correct |
5 ms |
2708 KB |
Output is correct |
47 |
Correct |
4 ms |
2648 KB |
Output is correct |
48 |
Correct |
4 ms |
2648 KB |
Output is correct |
49 |
Correct |
3 ms |
1844 KB |
Output is correct |
50 |
Correct |
5 ms |
2680 KB |
Output is correct |
51 |
Correct |
4 ms |
2648 KB |
Output is correct |
52 |
Correct |
4 ms |
2264 KB |
Output is correct |
53 |
Correct |
4 ms |
2480 KB |
Output is correct |
54 |
Correct |
3 ms |
2652 KB |
Output is correct |
55 |
Correct |
3 ms |
2652 KB |
Output is correct |
56 |
Correct |
4 ms |
2652 KB |
Output is correct |