Submission #415316

# Submission time Handle Problem Language Result Execution time Memory
415316 2021-05-31T21:26:56 Z Blagojce Martian DNA (BOI18_dna) C++11
100 / 100
43 ms 4500 KB
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
  
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pii;
const ll inf = 1e18;
const int i_inf = 1e9;
const ll mod = 1e9+7;

mt19937 _rand(time(NULL));
const int mxn = 2e5;

int n, k, r;

int a[mxn];
int c[mxn];

int cnt[mxn];

void solve(){
	cin >> n >> k >> r;	
	fr(i, 0, n){
		cin >> a[i];
	}
	fr(i, 0, r){
		int nuc;
		cin >> nuc >> c[nuc];
	}
	int in = 0;
	int p = 0;
	while(in < r && p < n){
		cnt[a[p]] ++;
		if(cnt[a[p]] == c[a[p]]){
			++in;
		}
		++p;
	}
	if(in < r){
		cout<<"impossible"<<endl;
		return;
	}
	--p;
	
	int ans = p+1;
	
	int l = 0;
	
	while(p < n){
		while(l < p && cnt[a[l]] > c[a[l]]){
			cnt[a[l]]--;
			++l;
		}
		ans = min(ans, p-l+1);
		
		++p;
		if(p < n){
			cnt[a[p]]++;
		}
	}
	cout<<ans<<endl;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	solve();
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 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 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 2 ms 372 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 1484 KB Output is correct
2 Correct 18 ms 1464 KB Output is correct
3 Correct 19 ms 1484 KB Output is correct
4 Correct 22 ms 1428 KB Output is correct
5 Correct 28 ms 2468 KB Output is correct
6 Correct 17 ms 1380 KB Output is correct
7 Correct 18 ms 1612 KB Output is correct
8 Correct 26 ms 3064 KB Output is correct
9 Correct 21 ms 2064 KB Output is correct
10 Correct 20 ms 1440 KB Output is correct
11 Correct 2 ms 328 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 324 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 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 3488 KB Output is correct
2 Correct 33 ms 3136 KB Output is correct
3 Correct 27 ms 2856 KB Output is correct
4 Correct 17 ms 1432 KB Output is correct
5 Correct 39 ms 3980 KB Output is correct
6 Correct 43 ms 4500 KB Output is correct
7 Correct 21 ms 2052 KB Output is correct
8 Correct 26 ms 2400 KB Output is correct
9 Correct 16 ms 1428 KB Output is correct
10 Correct 17 ms 1404 KB Output is correct
11 Correct 18 ms 1484 KB Output is correct
12 Correct 19 ms 1392 KB Output is correct
13 Correct 23 ms 2500 KB Output is correct
14 Correct 18 ms 1396 KB Output is correct
15 Correct 23 ms 1604 KB Output is correct
16 Correct 25 ms 3100 KB Output is correct
17 Correct 21 ms 1996 KB Output is correct
18 Correct 17 ms 1484 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 2 ms 320 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct