Submission #869209

# Submission time Handle Problem Language Result Execution time Memory
869209 2023-11-03T14:00:22 Z goodspeed0208 JJOOII 2 (JOI20_ho_t2) C++14
0 / 100
0 ms 348 KB
#include<iostream>
#include<vector>
#include<algorithm>
#define int long long
using namespace std;

signed main() {
	int n, k;
	cin >> n>> k;
	string s;
	cin >> s;
	vector<int>v(n);
	for (int i = 0 ; i < n ; i++) {
		if (s[i] == 'J') v[i] = 0;
		else if (s[i] == 'O') v[i] = 1;
		else v[i] = 2;
	}
	vector<vector<int> >num(n, vector<int>(3, 0));
	vector<vector<int> >pos(3);
	num[0][v[0]]++;
	pos[v[0]].push_back(0);
	for (int i = 1 ; i < n ; i++) {
		num[i] = num[i-1];
		num[i][v[i]] = num[i-1][v[i]]+1;
		pos[v[i]].push_back(i);
	} 
	int mn = -1;
	for (int i = 0 ; i < n ; i++) {
		for (int j = i+k*3-1 ; j < n ; j++) {
			int can = true;
			int numj, numi;
			if (i == 0) numj = 0;
			else numj = num[i-1][0];
			numi = num[j][2];
			if (numj + k > pos.size() || numi < k) {
				can = false;
				continue;
			}
			int posj = pos[0][(numj + k) - 1];
			int posi = pos[2][(numi - k + 1) - 1];
			if (num[posi][1] - num[posj][1] >= k) {
				//cout << i << " " << j << "\n";
				if (mn == -1) mn = j - i + 1;
				else mn = min(mn, j-i+1);
				break;
			}
		}
	}
	if (mn == -1) cout << "-1\n";
	else cout << mn - k * 3 << "\n";
}









Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:35:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |    if (numj + k > pos.size() || numi < k) {
      |        ~~~~~~~~~^~~~~~~~~~~~
ho_t2.cpp:30:8: warning: variable 'can' set but not used [-Wunused-but-set-variable]
   30 |    int can = true;
      |        ^~~
# 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 -