#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
int no_of_input,base_length,no_of_case;
int input1,input2;
vector<int> vect1;
cin >> no_of_input >> base_length >> no_of_case;
vector<int> minimum(base_length,0);
vector<int> countt(base_length,0);
for(int i=0;i<no_of_input;i++){
cin >> input1;
vect1.push_back(input1);
}
for(int i=0;i<no_of_case;i++){
cin >> input1 >> input2;
minimum[input1] = input2;
}
int currhas=base_length-no_of_case;
int pos1 = 0,pos2=0;
int ans = INT_MAX;
vector<int> temp(base_length,0);
for(int i=0;i<no_of_input;i++){
temp[vect1[i]]++;
}
for(int i=0;i<base_length;i++){
if(temp[i]<minimum[i]){
cout << "impossible";
return 0;
}
}
while(pos1<vect1.size()){
while(pos1<vect1.size()&&currhas<base_length){
if(countt[vect1[pos1]]==minimum[vect1[pos1]]-1){
currhas++;
}
countt[vect1[pos1]]++;
pos1++;
}
while(pos2<vect1.size()&&pos2<=pos1){
if(countt[vect1[pos2]]==minimum[vect1[pos2]]){
break;
}
if(pos1==pos2){
break;
}
countt[vect1[pos2]]--;
pos2++;
}
/*for(int i=0;i<countt.size();i++){
cout << countt[i] << " ";
}
cout << endl;
cout << pos1 << " " << pos2 << endl;*/
ans = min(ans,pos1-pos2);
if(pos1<vect1.size()){
countt[vect1[pos1]]++;
pos1++;
}
}
//cout << "-------------" << endl;
cout << ans;
}
Compilation message
dna.cpp: In function 'int32_t main()':
dna.cpp:34:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | while(pos1<vect1.size()){
| ~~~~^~~~~~~~~~~~~
dna.cpp:35:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | while(pos1<vect1.size()&&currhas<base_length){
| ~~~~^~~~~~~~~~~~~
dna.cpp:42:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | while(pos2<vect1.size()&&pos2<=pos1){
| ~~~~^~~~~~~~~~~~~
dna.cpp:58:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | if(pos1<vect1.size()){
| ~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
360 KB |
Output is correct |
2 |
Correct |
1 ms |
220 KB |
Output is correct |
3 |
Correct |
0 ms |
220 KB |
Output is correct |
4 |
Correct |
1 ms |
220 KB |
Output is correct |
5 |
Correct |
1 ms |
220 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
220 KB |
Output is correct |
8 |
Correct |
1 ms |
220 KB |
Output is correct |
9 |
Correct |
1 ms |
220 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
456 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
312 KB |
Output is correct |
7 |
Correct |
1 ms |
220 KB |
Output is correct |
8 |
Correct |
1 ms |
220 KB |
Output is correct |
9 |
Correct |
1 ms |
220 KB |
Output is correct |
10 |
Correct |
1 ms |
220 KB |
Output is correct |
11 |
Correct |
1 ms |
220 KB |
Output is correct |
12 |
Correct |
1 ms |
220 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
296 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
2744 KB |
Output is correct |
2 |
Correct |
36 ms |
2820 KB |
Output is correct |
3 |
Correct |
38 ms |
2836 KB |
Output is correct |
4 |
Correct |
35 ms |
2872 KB |
Output is correct |
5 |
Correct |
62 ms |
4892 KB |
Output is correct |
6 |
Correct |
34 ms |
2804 KB |
Output is correct |
7 |
Correct |
42 ms |
3092 KB |
Output is correct |
8 |
Correct |
68 ms |
7860 KB |
Output is correct |
9 |
Correct |
54 ms |
3264 KB |
Output is correct |
10 |
Correct |
34 ms |
2844 KB |
Output is correct |
11 |
Correct |
1 ms |
304 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
436 KB |
Output is correct |
15 |
Correct |
2 ms |
312 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
216 KB |
Output is correct |
23 |
Correct |
1 ms |
220 KB |
Output is correct |
24 |
Correct |
1 ms |
220 KB |
Output is correct |
25 |
Correct |
1 ms |
316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
5520 KB |
Output is correct |
2 |
Correct |
91 ms |
4848 KB |
Output is correct |
3 |
Correct |
72 ms |
4540 KB |
Output is correct |
4 |
Correct |
38 ms |
2860 KB |
Output is correct |
5 |
Correct |
111 ms |
6372 KB |
Output is correct |
6 |
Correct |
116 ms |
8192 KB |
Output is correct |
7 |
Correct |
57 ms |
3280 KB |
Output is correct |
8 |
Correct |
64 ms |
3684 KB |
Output is correct |
9 |
Correct |
34 ms |
2804 KB |
Output is correct |
10 |
Correct |
36 ms |
2788 KB |
Output is correct |
11 |
Correct |
37 ms |
2812 KB |
Output is correct |
12 |
Correct |
36 ms |
2796 KB |
Output is correct |
13 |
Correct |
63 ms |
4828 KB |
Output is correct |
14 |
Correct |
34 ms |
2768 KB |
Output is correct |
15 |
Correct |
38 ms |
3012 KB |
Output is correct |
16 |
Correct |
68 ms |
7880 KB |
Output is correct |
17 |
Correct |
54 ms |
3408 KB |
Output is correct |
18 |
Correct |
35 ms |
2764 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
476 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 |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
220 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |