8658 | 2024-01-25 00:54:20 | renn | Kutyavetélkedő | cpp17 | Wrong answer 34/100 | 131ms | 43640 KiB |
#include <bits/stdc++.h>
using namespace std;
inline bool cnt(unordered_set<int> &ehh, int &n) {
return ehh.find(n) != ehh.end();
}
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
int n, k, m, a, b;
cin >> n >> k;
vector<int> yey(n), yay(n+2);
vector<unordered_set<int>> ehh(k+1);
for(auto &x : yey) { cin >> x; x--; }
if(yey[0] == k && yey[1] == k) {
cout << "0\n";
exit(0);
}
yey.insert(yey.end(), {-1, -1});
cin >> m;
while(m--) {
cin >> a >> b;
a--; b--;
if(a == k || b == k) continue;
ehh[a].insert(b);
}
yay[yey[0] == k] = 1;
for(int i = 0; i < n; i++) {
if(yay[i] == -1) continue;
if(cnt(ehh[yey[i]], yey[i+1]))
yay[i+1] = max(yay[i+1], yay[i]+1);
if(cnt(ehh[yey[i]], yey[i+2]))
yay[i+2] = max(yay[i+2], yay[i]+1);
}
cout << max(0, max(yay[n-1], yay[n-2]));
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1832 KiB | ||||
2 | Accepted | 3ms | 2048 KiB | ||||
subtask2 | 0/15 | ||||||
3 | Accepted | 3ms | 2268 KiB | ||||
4 | Accepted | 3ms | 2604 KiB | ||||
5 | Accepted | 3ms | 2744 KiB | ||||
6 | Accepted | 3ms | 2960 KiB | ||||
7 | Wrong answer | 26ms | 7632 KiB | ||||
8 | Accepted | 27ms | 7840 KiB | ||||
9 | Accepted | 26ms | 8124 KiB | ||||
subtask3 | 0/19 | ||||||
10 | Accepted | 3ms | 3624 KiB | ||||
11 | Wrong answer | 2ms | 3628 KiB | ||||
12 | Accepted | 2ms | 3636 KiB | ||||
13 | Accepted | 3ms | 3728 KiB | ||||
14 | Accepted | 3ms | 3856 KiB | ||||
15 | Accepted | 3ms | 3848 KiB | ||||
16 | Accepted | 3ms | 3960 KiB | ||||
subtask4 | 34/34 | ||||||
17 | Accepted | 3ms | 4172 KiB | ||||
18 | Accepted | 4ms | 4328 KiB | ||||
19 | Accepted | 6ms | 4640 KiB | ||||
20 | Accepted | 6ms | 4900 KiB | ||||
21 | Accepted | 7ms | 5344 KiB | ||||
22 | Accepted | 7ms | 5644 KiB | ||||
subtask5 | 0/32 | ||||||
23 | Wrong answer | 46ms | 13104 KiB | ||||
24 | Accepted | 52ms | 16328 KiB | ||||
25 | Accepted | 54ms | 19224 KiB | ||||
26 | Wrong answer | 61ms | 22024 KiB | ||||
27 | Accepted | 59ms | 24348 KiB | ||||
28 | Wrong answer | 97ms | 19588 KiB | ||||
29 | Wrong answer | 131ms | 43544 KiB | ||||
30 | Wrong answer | 131ms | 43640 KiB | ||||
31 | Wrong answer | 79ms | 26524 KiB | ||||
32 | Accepted | 45ms | 13136 KiB | ||||
33 | Accepted | 107ms | 35164 KiB | ||||
34 | Accepted | 93ms | 35384 KiB |