8687 | 2024-01-25 12:00:35 | renn | Kutyavetélkedő | cpp17 | Accepted 100/100 | 142ms | 42884 KiB |
#include <bits/stdc++.h>
using namespace std;
inline bool cnt(unordered_set<int> &x, int &n) {
return x.find(n) != x.end();
}
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
int n, k, m, a, b;
cin >> n >> k;
vector<int> feladatok(n), legjobb(n+2, -1);
vector<unordered_set<int>> szabalyok(k+1);
for(auto &x : feladatok) { cin >> x; x--; }
if(feladatok[0] == k && feladatok[1] == k) {
cout << "0\n";
exit(0);
}
feladatok.insert(feladatok.end(), {-1, -1});
cin >> m;
while(m--) {
cin >> a >> b;
a--; b--;
if(a == k || b == k) continue;
szabalyok[a].insert(b);
}
legjobb[0] = feladatok[0] == k ? -1 : 1;
legjobb[1] = feladatok[1] == k ? -1 : 1;
for(int i = 0; i < n; i++) {
if(legjobb[i] == -1) continue;
if(cnt(szabalyok[feladatok[i]], feladatok[i+1]))
legjobb[i+1] = max(legjobb[i+1], legjobb[i]+1);
if(cnt(szabalyok[feladatok[i]], feladatok[i+2]))
legjobb[i+2] = max(legjobb[i+2], legjobb[i]+1);
}
cout << max(0, max(legjobb[n-1], legjobb[n-2]));
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1864 KiB | ||||
2 | Accepted | 3ms | 2152 KiB | ||||
subtask2 | 15/15 | ||||||
3 | Accepted | 3ms | 2372 KiB | ||||
4 | Accepted | 3ms | 2328 KiB | ||||
5 | Accepted | 3ms | 2420 KiB | ||||
6 | Accepted | 3ms | 2636 KiB | ||||
7 | Accepted | 19ms | 7424 KiB | ||||
8 | Accepted | 24ms | 7572 KiB | ||||
9 | Accepted | 24ms | 7436 KiB | ||||
subtask3 | 19/19 | ||||||
10 | Accepted | 3ms | 3016 KiB | ||||
11 | Accepted | 3ms | 3148 KiB | ||||
12 | Accepted | 3ms | 3212 KiB | ||||
13 | Accepted | 3ms | 3332 KiB | ||||
14 | Accepted | 3ms | 3428 KiB | ||||
15 | Accepted | 3ms | 3508 KiB | ||||
16 | Accepted | 2ms | 3504 KiB | ||||
subtask4 | 34/34 | ||||||
17 | Accepted | 3ms | 3592 KiB | ||||
18 | Accepted | 4ms | 3944 KiB | ||||
19 | Accepted | 6ms | 4512 KiB | ||||
20 | Accepted | 6ms | 4728 KiB | ||||
21 | Accepted | 6ms | 5084 KiB | ||||
22 | Accepted | 6ms | 5280 KiB | ||||
subtask5 | 32/32 | ||||||
23 | Accepted | 41ms | 12704 KiB | ||||
24 | Accepted | 46ms | 16144 KiB | ||||
25 | Accepted | 50ms | 18956 KiB | ||||
26 | Accepted | 52ms | 21380 KiB | ||||
27 | Accepted | 54ms | 23480 KiB | ||||
28 | Accepted | 89ms | 18768 KiB | ||||
29 | Accepted | 142ms | 42792 KiB | ||||
30 | Accepted | 123ms | 42884 KiB | ||||
31 | Accepted | 71ms | 25764 KiB | ||||
32 | Accepted | 43ms | 12428 KiB | ||||
33 | Accepted | 100ms | 34484 KiB | ||||
34 | Accepted | 98ms | 34544 KiB |