Submission #577058

# Submission time Handle Problem Language Result Execution time Memory
577058 2022-06-14T00:51:45 Z Pietra Martian DNA (BOI18_dna) C++14
40 / 100
37 ms 3156 KB
#include<bits/stdc++.h>
using namespace std ; 

const int maxn = 1e5 + 5 ; 

int n, k, r, freq[maxn], v[maxn], qtd[maxn] ; 

bool check(int x){

	// cout << x << ":\n" ;

	for(int i = 0 ; i <= k ; i++) freq[i] = 0 ; 

	int ct = 0 ; 

	for(int i = 1 ; i <= x ; i++){
		freq[v[i]]++ ; 
		if(freq[v[i]] == qtd[v[i]]) ct++ ;   
	}

	if(r == ct) return 1 ; 

	for(int i = x + 1 ; i <= n ; i++){
		if(freq[v[i-x]] == qtd[v[i-x]]) ct-- ; 
		freq[v[i-x]]-- ; freq[v[i]]++ ;  
		if(freq[v[i]] == qtd[v[i]]) ct++ ; 
		// cout << "pos " << i << " " << ct << " " ; 
		if(r == ct) return 1 ; 
	}

	// cout << "\n" << ct << "\n" ; 

	if(r == ct) return 1 ; 

	return 0 ; 

}

int main(){

	ios_base::sync_with_stdio(false) ; cin.tie(NULL) ; 
	
	cin >> n >> k >> r ; 

	for(int i = 1 ; i <= n ; i++) cin >> v[i] ; 

	for(int i = 1 ; i <= r ; i++){
		int v, f ; cin >> v >> f ; 
		qtd[v] = f ; 
	}

	int ini = 1, fim = n, mid, best = -1 ; 

	while(ini <= fim){
		mid = (ini + fim)>>1 ; 
		if(check(mid)) best = mid, fim = mid - 1 ; 
		else ini = mid + 1 ;
	} 

	if(best == -1) cout << "impossible\n" ; 
	else cout << best << "\n" ; 

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 328 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 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 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 1488 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 34 ms 3156 KB Output is correct
2 Incorrect 37 ms 2892 KB Output isn't correct
3 Halted 0 ms 0 KB -