#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define test(args...) abc("[" + string(#args) + "]", args)
void abc() {cerr << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
cerr << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
while (l != r) cerr << *l << " \n"[++l == r];
}
const int mod = 1e9 + 7, N = 200000;
int main () {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, k;
cin >> n >> m >> k;
vector <int> a(n), need(m, 0);
for (int i = 0; i < n; ++i) cin >> a[i];
for (int i = 0, v, c; i < k; ++i) {
cin >> v >> c;
need[v] = c;
}
vector <int> cnt(m, 0);
int ok = k, ans = n + 1;
auto add = [&](int v) {
cnt[v]++;
if (cnt[v] == need[v]) ok--;
};
auto del = [&](int v) {
if (cnt[v] == need[v]) ok++;
cnt[v]--;
};
for (int i = 0, j = 0; i < n; ++i) {
while (ok && j < n) {
add(a[j++]);
}
if (!ok) ans = min(ans, j - i);
del(a[i]);
}
if (ans == n + 1) cout << "impossible\n";
else cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
312 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
1484 KB |
Output is correct |
2 |
Correct |
17 ms |
1496 KB |
Output is correct |
3 |
Correct |
18 ms |
1456 KB |
Output is correct |
4 |
Correct |
18 ms |
1524 KB |
Output is correct |
5 |
Correct |
24 ms |
2816 KB |
Output is correct |
6 |
Correct |
17 ms |
1484 KB |
Output is correct |
7 |
Correct |
18 ms |
1604 KB |
Output is correct |
8 |
Correct |
26 ms |
3944 KB |
Output is correct |
9 |
Correct |
21 ms |
2020 KB |
Output is correct |
10 |
Correct |
17 ms |
1500 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
332 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 |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
3452 KB |
Output is correct |
2 |
Correct |
33 ms |
3140 KB |
Output is correct |
3 |
Correct |
27 ms |
2856 KB |
Output is correct |
4 |
Correct |
17 ms |
1484 KB |
Output is correct |
5 |
Correct |
43 ms |
3912 KB |
Output is correct |
6 |
Correct |
56 ms |
4548 KB |
Output is correct |
7 |
Correct |
24 ms |
2124 KB |
Output is correct |
8 |
Correct |
27 ms |
2364 KB |
Output is correct |
9 |
Correct |
16 ms |
1484 KB |
Output is correct |
10 |
Correct |
18 ms |
1476 KB |
Output is correct |
11 |
Correct |
18 ms |
1484 KB |
Output is correct |
12 |
Correct |
17 ms |
1472 KB |
Output is correct |
13 |
Correct |
23 ms |
2764 KB |
Output is correct |
14 |
Correct |
16 ms |
1480 KB |
Output is correct |
15 |
Correct |
18 ms |
1612 KB |
Output is correct |
16 |
Correct |
28 ms |
3904 KB |
Output is correct |
17 |
Correct |
21 ms |
2128 KB |
Output is correct |
18 |
Correct |
19 ms |
1484 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
320 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 |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |