# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
577059 |
2022-06-14T00:53:26 Z |
Pietra |
Martian DNA (BOI18_dna) |
C++14 |
|
54 ms |
4480 KB |
#include<bits/stdc++.h>
using namespace std ;
const int maxn = 2e5 + 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++ ;
if(r == ct) return 1 ;
}
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 |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 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 |
340 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 |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
1108 KB |
Output is correct |
2 |
Correct |
23 ms |
1492 KB |
Output is correct |
3 |
Correct |
15 ms |
1492 KB |
Output is correct |
4 |
Correct |
20 ms |
1456 KB |
Output is correct |
5 |
Correct |
31 ms |
2656 KB |
Output is correct |
6 |
Correct |
20 ms |
1492 KB |
Output is correct |
7 |
Correct |
22 ms |
1668 KB |
Output is correct |
8 |
Correct |
35 ms |
3128 KB |
Output is correct |
9 |
Correct |
25 ms |
2108 KB |
Output is correct |
10 |
Correct |
26 ms |
1492 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
324 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
1716 KB |
Output is correct |
2 |
Correct |
40 ms |
1492 KB |
Output is correct |
3 |
Correct |
48 ms |
2784 KB |
Output is correct |
4 |
Correct |
10 ms |
1428 KB |
Output is correct |
5 |
Correct |
41 ms |
4036 KB |
Output is correct |
6 |
Correct |
54 ms |
4480 KB |
Output is correct |
7 |
Correct |
28 ms |
2072 KB |
Output is correct |
8 |
Correct |
39 ms |
2308 KB |
Output is correct |
9 |
Correct |
20 ms |
1456 KB |
Output is correct |
10 |
Correct |
23 ms |
1420 KB |
Output is correct |
11 |
Correct |
14 ms |
1492 KB |
Output is correct |
12 |
Correct |
21 ms |
1412 KB |
Output is correct |
13 |
Correct |
31 ms |
2612 KB |
Output is correct |
14 |
Correct |
19 ms |
1512 KB |
Output is correct |
15 |
Correct |
21 ms |
1620 KB |
Output is correct |
16 |
Correct |
36 ms |
3228 KB |
Output is correct |
17 |
Correct |
26 ms |
1996 KB |
Output is correct |
18 |
Correct |
25 ms |
1492 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
0 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
324 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |