# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
535299 |
2022-03-10T01:12:22 Z |
Koying |
JJOOII 2 (JOI20_ho_t2) |
C++14 |
|
2000 ms |
652 KB |
#include <bits/stdc++.h>
#define int long long
#pragma GCC optimize("Ofast")
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
#define cmax(a, b) a = max(a, b)
#define cmin(a, b) a = min(a, b)
#define MEM(x, n) memset(x, n, sizeof(x))
#define pii pair<int, int>
#define pdd pair<double, double>
#define DB(x) cerr << #x << " " << x << endl;
#define endl "\n"
#define Koying ios::sync_with_stdio(0), cin.tie(0)
#define lowbit(x) x &(-x)
const int INF = 0x3f3f3f3f3f3f3f3f;
using namespace std;
#define MAXN 200005
int n, k;
string s;
void sol() {
cin >> n >> k;
cin >> s;
int mn = INF;
//DB(s);
for (int i = 0; i <= n - k * 3; i++) {
if (s[i] != 'J')
continue;
int a, b, c;
a = b = c = 0;
for (int j = i; j < n; j++) {
if (a < k) {
a += (s[j] == 'J');
//DB(a);
}
else if (b < k) {
b += s[j] == 'O';
}
else if (c < k) {
c += s[j] == 'I';
}
if (a == k && b == k && c == k) {
cmin(mn, j - i + 1);
break;
}
}
//cout << a << " " << b << " " << c << endl;
}
if (mn == INF) {
cout << -1 << endl;
return;
}
cout << mn - 3 * k << endl;
}
signed main()
{
Koying;
int t = 1;
//cin >> t;
sol();
return 0;
}
Compilation message
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:61:9: warning: unused variable 't' [-Wunused-variable]
61 | int t = 1;
| ^
# |
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 |
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 |
1 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 |
0 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 |
1 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 |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
2 ms |
212 KB |
Output is correct |
22 |
Correct |
2 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
2 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
212 KB |
Output is correct |
26 |
Correct |
2 ms |
212 KB |
Output is correct |
27 |
Correct |
2 ms |
324 KB |
Output is correct |
28 |
Correct |
2 ms |
212 KB |
Output is correct |
29 |
Correct |
2 ms |
212 KB |
Output is correct |
30 |
Correct |
2 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
2 ms |
212 KB |
Output is correct |
33 |
Correct |
2 ms |
328 KB |
Output is correct |
34 |
Correct |
4 ms |
212 KB |
Output is correct |
35 |
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 |
0 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 |
1 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 |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
2 ms |
212 KB |
Output is correct |
22 |
Correct |
2 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
2 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
212 KB |
Output is correct |
26 |
Correct |
2 ms |
212 KB |
Output is correct |
27 |
Correct |
2 ms |
324 KB |
Output is correct |
28 |
Correct |
2 ms |
212 KB |
Output is correct |
29 |
Correct |
2 ms |
212 KB |
Output is correct |
30 |
Correct |
2 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
2 ms |
212 KB |
Output is correct |
33 |
Correct |
2 ms |
328 KB |
Output is correct |
34 |
Correct |
4 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
3 ms |
608 KB |
Output is correct |
37 |
Correct |
4 ms |
652 KB |
Output is correct |
38 |
Correct |
3 ms |
608 KB |
Output is correct |
39 |
Execution timed out |
2061 ms |
608 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |