#include <bits/stdc++.h>
using namespace std;
#define max(a, b) (a > b ? a : b)
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, k, r;cin>>n>>k>>r;
int* dna = new int[n];
for (int i = 0;i < n;i++)
cin >> dna[i];
unordered_set<int> hset;
unordered_map<int, int> req;
unordered_set<int> sreq;
for (int i = 0;i < r;i++)
{
int x, y;
cin >> x >> y;
hset.emplace(x);
req[x] = y;
sreq.emplace(x);
}
int min_len = 1e9;
int j = -1;
for (int i = 0;i < n;i++)
{
if (i && hset.count(dna[i-1]))
{
req[dna[i-1]]++;
if (req[dna[i-1]] > 0)
sreq.emplace(dna[i-1]);
}
if (sreq.size())
for (j=j+1;j < n;j++)
{
if (hset.count(dna[j]))
{
req[dna[j]]--;
if (req[dna[j]] <= 0)
sreq.erase(dna[j]);
}
if (!sreq.size()) {
min_len = min(min_len, j - i + 1);
break;
}
}
else
min_len = min(min_len, j - i + 1);
}
if (min_len == 1e9)
cout << "impossible";
else if (min_len)
cout << min_len;
else if (min_len == 0)
cout << "impossible";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
452 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
456 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 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 |
464 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 |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
456 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
456 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
1628 KB |
Output is correct |
2 |
Correct |
17 ms |
1628 KB |
Output is correct |
3 |
Correct |
18 ms |
1628 KB |
Output is correct |
4 |
Correct |
18 ms |
1672 KB |
Output is correct |
5 |
Correct |
19 ms |
2392 KB |
Output is correct |
6 |
Correct |
18 ms |
1628 KB |
Output is correct |
7 |
Correct |
16 ms |
1624 KB |
Output is correct |
8 |
Correct |
20 ms |
2648 KB |
Output is correct |
9 |
Correct |
17 ms |
2136 KB |
Output is correct |
10 |
Correct |
18 ms |
1880 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 |
464 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
456 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
92 ms |
11908 KB |
Output is correct |
2 |
Correct |
56 ms |
10372 KB |
Output is correct |
3 |
Correct |
33 ms |
4700 KB |
Output is correct |
4 |
Correct |
17 ms |
1628 KB |
Output is correct |
5 |
Correct |
63 ms |
12676 KB |
Output is correct |
6 |
Correct |
139 ms |
16768 KB |
Output is correct |
7 |
Correct |
27 ms |
3160 KB |
Output is correct |
8 |
Correct |
31 ms |
4180 KB |
Output is correct |
9 |
Correct |
17 ms |
1624 KB |
Output is correct |
10 |
Correct |
16 ms |
1628 KB |
Output is correct |
11 |
Correct |
19 ms |
1628 KB |
Output is correct |
12 |
Correct |
19 ms |
1656 KB |
Output is correct |
13 |
Correct |
19 ms |
2268 KB |
Output is correct |
14 |
Correct |
18 ms |
1600 KB |
Output is correct |
15 |
Correct |
15 ms |
1628 KB |
Output is correct |
16 |
Correct |
20 ms |
2468 KB |
Output is correct |
17 |
Correct |
17 ms |
2136 KB |
Output is correct |
18 |
Correct |
21 ms |
1628 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
464 KB |
Output is correct |
25 |
Correct |
0 ms |
460 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
456 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |