#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define uniq(x) x.erase(unique(all(x)), x.end())
#define rall(x) x.rbegin(), x.rend()
//#define int long long
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
const double eps = 1e-9;
void setIO() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
int32_t main() {
setIO();
int n, k, r;
cin >> n >> k >> r;
vector<int> v(n);
for(int &x : v) cin >> x;
vector<int> need(k, 0);
vector<bool> vis(k, 0);
for(int i=0; i<r; i++) {
int a, b;
cin >> a >> b;
need[a] = b;
vis[a] = 1;
}
int ans = 1e9;
vector<int> cnt(k, 0);
int ok = 0;
int j=0;
for(int i=0; i<n; i++) {
while(j < n && ok < r) {
cnt[v[j]]++;
if(vis[v[j]]) ok += (cnt[v[j]] == need[v[j]]);
j++;
}
//cout << i+1 << " " << j << '\n';
if(ok == r) ans = min(ans, j - i);
cnt[v[i]]--;
if(vis[v[i]]) ok -= (cnt[v[i]] == need[v[i]] - 1);
}
if(ans == 1e9) cout << "impossible\n";
else cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
452 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
456 KB |
Output is correct |
7 |
Correct |
0 ms |
452 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1628 KB |
Output is correct |
2 |
Correct |
10 ms |
1880 KB |
Output is correct |
3 |
Correct |
11 ms |
1628 KB |
Output is correct |
4 |
Correct |
10 ms |
1624 KB |
Output is correct |
5 |
Correct |
13 ms |
2908 KB |
Output is correct |
6 |
Correct |
9 ms |
1628 KB |
Output is correct |
7 |
Correct |
10 ms |
1628 KB |
Output is correct |
8 |
Correct |
15 ms |
3932 KB |
Output is correct |
9 |
Correct |
12 ms |
2136 KB |
Output is correct |
10 |
Correct |
11 ms |
1500 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 |
504 KB |
Output is correct |
14 |
Correct |
1 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
3420 KB |
Output is correct |
2 |
Correct |
19 ms |
3156 KB |
Output is correct |
3 |
Correct |
17 ms |
2908 KB |
Output is correct |
4 |
Correct |
10 ms |
1624 KB |
Output is correct |
5 |
Correct |
23 ms |
4172 KB |
Output is correct |
6 |
Correct |
25 ms |
4816 KB |
Output is correct |
7 |
Correct |
13 ms |
2256 KB |
Output is correct |
8 |
Correct |
16 ms |
2396 KB |
Output is correct |
9 |
Correct |
9 ms |
1624 KB |
Output is correct |
10 |
Correct |
9 ms |
1628 KB |
Output is correct |
11 |
Correct |
10 ms |
1628 KB |
Output is correct |
12 |
Correct |
9 ms |
1628 KB |
Output is correct |
13 |
Correct |
14 ms |
3032 KB |
Output is correct |
14 |
Correct |
9 ms |
1628 KB |
Output is correct |
15 |
Correct |
10 ms |
1628 KB |
Output is correct |
16 |
Correct |
15 ms |
4100 KB |
Output is correct |
17 |
Correct |
11 ms |
2140 KB |
Output is correct |
18 |
Correct |
9 ms |
1628 KB |
Output is correct |
19 |
Correct |
0 ms |
456 KB |
Output is correct |
20 |
Correct |
0 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
496 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
460 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
604 KB |
Output is correct |