Submission #748240

# Submission time Handle Problem Language Result Execution time Memory
748240 2023-05-25T20:36:03 Z JellyTheOctopus Martian DNA (BOI18_dna) C++17
0 / 100
85 ms 2360 KB
#include <bits/stdc++.h>
using namespace std;

int N, K, R;

int main() {
	cin >> N >> K >> R;
	vector<int> arr(N);
	for (int i = 0; i < N; i++) {
		cin >> arr[i];
	}
	vector<int> need(K, INT_MAX);
	for (int i = 0; i < R; i++) {
		int B, Q;
		cin >> B >> Q;
		need[B] = Q;
	}
	deque<int> d;
	vector<int> freq(K);
	int done = 0;
	int i = 0;
	int ans = INT_MAX;
	while (i < N) {
		while (done < R && i+1 < N) {
			d.push_back(i);
			freq[arr[i]]++;
			if (freq[arr[i]] == need[arr[i]]) {
				done++;
			}
			i++;
		}
		while (done == R) {
			int j = d.front();
			d.pop_front();
			freq[arr[j]]--;
			ans = min(ans, i-j);
			if (freq[arr[j]] == need[arr[j]]-1) {
				done--;
				break;
			}
		}
		i++;
	}
	if (ans == INT_MAX) {
		cout << "impossible\n";
	}
	else {
		cout << ans << "\n";
	}
}
# 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 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 1476 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 85 ms 2360 KB Output isn't correct
2 Halted 0 ms 0 KB -