Submission #288763

# Submission time Handle Problem Language Result Execution time Memory
288763 2020-09-01T21:12:38 Z luciocf JJOOII 2 (JOI20_ho_t2) C++14
0 / 100
1 ms 256 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 3e3+10;
const int inf = 1e9+10;

int n, k;
vector<int> pos[3];

int get_next(int ind, int p)
{
	auto it = lower_bound(pos[ind].begin(), pos[ind].end(), p);
	if (it == pos[ind].end()) return -1;

	int x = (int)(it-pos[ind].begin());

	if (x+k-1 >= pos[ind].size()) return -1;

	return pos[ind][x+k-1];
}

int main(void)
{
	string s;

	cin >> n >> k >> s;

	int ans = inf;

	for (int i = 0; i < n; i++)
	{
		if (s[i] == 'J') pos[0].push_back(i);
		else if (s[i] == 'O') pos[1].push_back(i);
		else pos[2].push_back(i);

		if (pos[0].size() < k) continue;

		int p = get_next(0, 0);
		if (p == -1) continue;

		p = get_next(1, p+1);
		if (p == -1) continue;

		p = get_next(2, p+1);
		if (p == -1) continue;

		ans = min(ans, p-pos[0][0]+1-3*k);
	}

	if (ans != -1) cout << ans << "\n";
	else cout << "-1\n";
}

Compilation message

ho_t2.cpp: In function 'int get_next(int, int)':
ho_t2.cpp:18:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |  if (x+k-1 >= pos[ind].size()) return -1;
      |      ~~~~~~^~~~~~~~~~~~~~~~~~
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:37:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   37 |   if (pos[0].size() < k) continue;
      |       ~~~~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Incorrect 1 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Incorrect 1 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Incorrect 1 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -