Submission #453776

# Submission time Handle Problem Language Result Execution time Memory
453776 2021-08-04T18:44:07 Z Hamed5001 Martian DNA (BOI18_dna) C++14
100 / 100
49 ms 1900 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int mxN = 2e5+10;
int N, K, R;

void solve() {
	cin >> N >> K >> R;
	vector<int> DNA(N), need(K, INT_MAX);

	for (auto& dna : DNA) 
		cin >> dna;

	for (int i = 0; i < R; i++) {
		int B, Q;
		cin >> B >> Q;
		need[B] = Q; 
	}

	int ans = INT_MAX;
	int good = 0;
	
	for (int l = 0, r = 0; l < N; l++) {
		while(good < R && r < N)
			if (--need[DNA[r++]] == 0)
				++good;

		if (good == R)
			ans = min(ans, r - l);

		if (++need[DNA[l]] == 1)
			--good;
	}

	cout << (ans == INT_MAX ? "impossible" : to_string(ans));
}	

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 252 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 1100 KB Output is correct
2 Correct 17 ms 1100 KB Output is correct
3 Correct 17 ms 1100 KB Output is correct
4 Correct 17 ms 1100 KB Output is correct
5 Correct 21 ms 1356 KB Output is correct
6 Correct 17 ms 1100 KB Output is correct
7 Correct 17 ms 1100 KB Output is correct
8 Correct 24 ms 1900 KB Output is correct
9 Correct 20 ms 1100 KB Output is correct
10 Correct 18 ms 1100 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 1356 KB Output is correct
2 Correct 31 ms 1328 KB Output is correct
3 Correct 25 ms 1344 KB Output is correct
4 Correct 16 ms 1100 KB Output is correct
5 Correct 37 ms 1484 KB Output is correct
6 Correct 49 ms 1740 KB Output is correct
7 Correct 22 ms 1100 KB Output is correct
8 Correct 27 ms 1148 KB Output is correct
9 Correct 18 ms 1100 KB Output is correct
10 Correct 17 ms 1100 KB Output is correct
11 Correct 18 ms 1100 KB Output is correct
12 Correct 17 ms 1100 KB Output is correct
13 Correct 21 ms 1356 KB Output is correct
14 Correct 16 ms 1100 KB Output is correct
15 Correct 19 ms 1052 KB Output is correct
16 Correct 29 ms 1868 KB Output is correct
17 Correct 20 ms 1100 KB Output is correct
18 Correct 17 ms 1100 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct