#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, k, r;
cin>>n>>k>>r;
int a[n], b[k+1], visited[k+1];
memset(visited, 0, sizeof(visited));
set<int>barani;
for(int i=0; i<k+1; i++)
b[i]=-1;
for(int i=0; i<n; i++)
{
cin>>a[i];
}
for(int i=0; i<r; i++)
{
int aa, bb;
cin>>aa>>bb;
b[aa]=bb;
barani.insert(aa);
}
int vishok=0, manjak=barani.size(), rez=INT_MAX;
for(int r=0, l=0; r<n; r++)
{
/*bool kiki=0;
while(l<r && manjak==0)
{
if(barani.find(a[l])!=barani.end())
{
visited[a[l]]--;
if(visited[a[l]]==b[a[l]]-1)
{
manjak++;
kiki=1;
visited[a[l]]++;
l--;
}
}
l++;
}
if(kiki)
manjak=0;
if(manjak==0)
{
rez=min(r-l, rez);
}*/
if(barani.find(a[r])!=barani.end())
{
visited[a[r]]++;
if(visited[a[r]]==b[a[r]])
{
manjak--;
}
}
if(manjak==0)
{
while(l<r && manjak==0)
{
if(barani.find(a[l])!=barani.end())
{
visited[a[l]]--;
if(visited[a[l]]==b[a[l]]-1)
{
manjak++;
}
}
l++;
}
if(manjak>0)
rez=min(r-l+2, rez);
}
}
/*if(manjak==0)
{
rez=min(r-l, rez);
}*/
if(rez==INT_MAX)
cout<<"impossible";
else
cout<<rez;
return 0;
}
Compilation message
dna.cpp: In function 'int main()':
dna.cpp:24:9: warning: unused variable 'vishok' [-Wunused-variable]
24 | int vishok=0, manjak=barani.size(), rez=INT_MAX;
| ^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
440 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
420 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
1732 KB |
Output is correct |
2 |
Correct |
20 ms |
1368 KB |
Output is correct |
3 |
Correct |
24 ms |
1628 KB |
Output is correct |
4 |
Correct |
19 ms |
1368 KB |
Output is correct |
5 |
Correct |
38 ms |
2900 KB |
Output is correct |
6 |
Correct |
20 ms |
1372 KB |
Output is correct |
7 |
Correct |
24 ms |
1624 KB |
Output is correct |
8 |
Correct |
40 ms |
3924 KB |
Output is correct |
9 |
Correct |
35 ms |
2144 KB |
Output is correct |
10 |
Correct |
23 ms |
1372 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
126 ms |
7252 KB |
Output is correct |
2 |
Correct |
107 ms |
5972 KB |
Output is correct |
3 |
Correct |
75 ms |
3668 KB |
Output is correct |
4 |
Incorrect |
19 ms |
1640 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |