Submission #689958

# Submission time Handle Problem Language Result Execution time Memory
689958 2023-01-29T21:49:06 Z NK_ Martian DNA (BOI18_dna) C++17
100 / 100
171 ms 21968 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>

using namespace std;

#define nl '\n'

int main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int N, K, R; cin >> N >> K >> R;

	vector<int> A(N); for(auto& x : A) cin >> x;

	vector<vector<int>> oc(K); for(int i = 0; i < N; i++) oc[A[i]].push_back(i);
	
	vector<int> Q(K, -1); 
	for(int i = 0; i < R; i++) {
		int x, y; cin >> x >> y; Q[x] = --y;
	}

	set<int> S; 
	for(int i = 0; i < K; i++) {
		if (Q[i] == -1) continue;
		if (Q[i] >= size(oc[i])) {
			cout << "impossible" << nl;
			return 0;
		}
		S.insert(oc[i][Q[i]]);
	}

	int ans = N + 1;
	for(int l = 0; l < N; l++) {
		int x = A[l];

		int r = *rbegin(S);
		ans = min(ans, r - l + 1);

		S.erase(oc[x][Q[x]]);
		++Q[x];
		if (Q[x] >= size(oc[x])) break;
		S.insert(oc[x][Q[x]]);
	}

	cout << ans << nl;

    return 0;
}

/*
13 4 3 
1 1 3 2 0 1 2 0 0 0 0 3 1  
0 2
2 1
1 2

5 3 1 
1 2 0 1 2  
0 2

*/

Compilation message

dna.cpp: In function 'int main()':
dna.cpp:25:12: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |   if (Q[i] >= size(oc[i])) {
dna.cpp:41:12: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |   if (Q[x] >= size(oc[x])) break;
# 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 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 0 ms 320 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 320 KB Output is correct
13 Correct 0 ms 316 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 2352 KB Output is correct
2 Correct 18 ms 2704 KB Output is correct
3 Correct 28 ms 2520 KB Output is correct
4 Correct 22 ms 2764 KB Output is correct
5 Correct 54 ms 10784 KB Output is correct
6 Correct 11 ms 2640 KB Output is correct
7 Correct 12 ms 2644 KB Output is correct
8 Correct 72 ms 19020 KB Output is correct
9 Correct 55 ms 3852 KB Output is correct
10 Correct 25 ms 2644 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 2 ms 608 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 320 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 9556 KB Output is correct
2 Correct 88 ms 9016 KB Output is correct
3 Correct 74 ms 8788 KB Output is correct
4 Correct 19 ms 2620 KB Output is correct
5 Correct 43 ms 9156 KB Output is correct
6 Correct 171 ms 21968 KB Output is correct
7 Correct 26 ms 3904 KB Output is correct
8 Correct 60 ms 5268 KB Output is correct
9 Correct 18 ms 2744 KB Output is correct
10 Correct 18 ms 2696 KB Output is correct
11 Correct 28 ms 2584 KB Output is correct
12 Correct 21 ms 2760 KB Output is correct
13 Correct 45 ms 10668 KB Output is correct
14 Correct 18 ms 2696 KB Output is correct
15 Correct 15 ms 2616 KB Output is correct
16 Correct 83 ms 19032 KB Output is correct
17 Correct 60 ms 3968 KB Output is correct
18 Correct 22 ms 2644 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 2 ms 724 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 320 KB Output is correct
33 Correct 1 ms 212 KB Output is correct