Submission #378268

# Submission time Handle Problem Language Result Execution time Memory
378268 2021-03-16T11:07:34 Z negar_a Martian DNA (BOI18_dna) C++14
100 / 100
199 ms 15212 KB
//!yrt tsuj uoy srettam gnihton no emoc
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define pii pair <int, int>
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define F first
#define S second

const int maxn = 2e5 + 5;
int a[maxn], t[maxn], l[maxn], ind[maxn];
int b[maxn], q[maxn], f[maxn], nxt[maxn];

int main(){
	fast_io;
	int n, k, r;
	cin >> n >> k >> r;
	for(int i = 0; i < n; i ++){
		cin >> a[i];
		ind[a[i]] = l[a[i]] = -1;
	}
	for(int i = 0; i < r; i ++){
		cin >> b[i] >> q[i];
		ind[b[i]] = i;
	}
	
	int ans = INT_MAX;
	set <int> s, cor;
	for(int i = 0; i < n; i ++){
		t[a[i]] ++;
		if(ind[a[i]] != -1){
			if(l[a[i]] == -1){
				f[a[i]] = i;
			}
			if(l[a[i]] != -1){
				nxt[l[a[i]]] = i;
			}
			l[a[i]] = i;
			s.insert(i);
			
			if(t[a[i]] >= q[ind[a[i]]]){
				cor.insert(a[i]);
			}
			if(t[a[i]] > q[ind[a[i]]]){
				t[a[i]] --;
				s.erase(f[a[i]]);
				f[a[i]] = nxt[f[a[i]]];
			}
		}
//		cout << i << " -> " << *s.begin() << endl;
		if((int)cor.size() >= r){
//			cout << i << " :: " << *s.begin() << endl;
			ans = min(ans, i - *s.begin() + 1);
		}
	}
	if(ans == INT_MAX){
		cout << "impossible";
		return 0;
	}
	cout << ans;
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 6144 KB Output is correct
2 Correct 52 ms 3820 KB Output is correct
3 Correct 38 ms 1900 KB Output is correct
4 Correct 65 ms 4716 KB Output is correct
5 Correct 22 ms 2156 KB Output is correct
6 Correct 58 ms 11372 KB Output is correct
7 Correct 21 ms 2156 KB Output is correct
8 Correct 24 ms 3564 KB Output is correct
9 Correct 19 ms 1792 KB Output is correct
10 Correct 72 ms 5484 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 199 ms 10988 KB Output is correct
2 Correct 179 ms 8812 KB Output is correct
3 Correct 58 ms 4588 KB Output is correct
4 Correct 25 ms 1900 KB Output is correct
5 Correct 73 ms 11628 KB Output is correct
6 Correct 173 ms 15212 KB Output is correct
7 Correct 132 ms 6380 KB Output is correct
8 Correct 130 ms 5228 KB Output is correct
9 Correct 60 ms 6124 KB Output is correct
10 Correct 52 ms 3820 KB Output is correct
11 Correct 36 ms 1900 KB Output is correct
12 Correct 59 ms 4716 KB Output is correct
13 Correct 21 ms 2156 KB Output is correct
14 Correct 58 ms 11372 KB Output is correct
15 Correct 21 ms 2156 KB Output is correct
16 Correct 26 ms 3564 KB Output is correct
17 Correct 19 ms 1772 KB Output is correct
18 Correct 69 ms 5484 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct