Submission #1031737

# Submission time Handle Problem Language Result Execution time Memory
1031737 2024-07-23T06:15:09 Z juicy JJOOII 2 (JOI20_ho_t2) C++17
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int N = 2e5 + 5;

int n, k;
string s;
array<int, 3> nxt[N];

int conv(char c) {
	return c == 'J' ? 0 : (c == 'O' ? 1 : 2);
}

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	
	cin >> n >> k >> s;
	array<int, 3> lst = {n + 1, n + 1, n + 1};
	for (int i = n; i >= 1; --i) {
		nxt[i] = lst;
		lst[conv(s[i - 1])] = i;
	}
	nxt[0] = lst;
	int p = 0;
	for (int j = 0; j < 3; ++j) {
		for (int i = 0; i < k; ++i) {
			p = nxt[p][j];
			if (p == n + 1) {
				cout << -1;
				exit(0);
			}
		}
	}
	cout << n - k * 3 - nxt[0][0] + 1 - n + p;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -