Submission #1031743

# Submission time Handle Problem Language Result Execution time Memory
1031743 2024-07-23T06:24:26 Z juicy JJOOII 2 (JOI20_ho_t2) C++17
0 / 100
1 ms 604 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;
int jump[N];
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};
	vector<vector<int>> pos(3);
	for (int i = n; i >= 1; --i) {
		nxt[i] = lst;
		int c = conv(s[i - 1]);
		lst[c] = i;
		pos[c].push_back(i);
		if (pos[c].size() >= k) {
			jump[i] = pos[c].end()[-k];
		} else {
			jump[i] = n + 1;
		}
	}
	int ans = 1e9;
	for (int i = 0; i < N; ++i) {
		if (s[i] == 'J') {
			int p = i + 1;
			for (int j = 0; j < 3; ++j) {
				p = jump[p];
				if (p == n + 1) {
					break;
				}
				if (j + 1 < 3) {
					p = nxt[p][j + 1];
				}
				if (p == n + 1) {
					break;
				}
			}
			if (p != n + 1) {
				ans = min(ans, n - 3 * k - i - n + p);
			}
		}
 	}
	cout <<  (ans == 1e9 ? -1 : ans);
	return 0;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:33:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   33 |   if (pos[c].size() >= k) {
      |       ~~~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -