8662 | 2024-01-25 01:11:38 | renn | Kutyavetélkedő | cpp17 | Wrong answer 49/100 | 93ms | 42440 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[feladatok[0] == k] = 1;
for(int i = 0, j = 0; i < n; i++) {
if(j == 2) {
cout << "0\n";
exit(0);
}
if(legjobb[i] == -1) {
j++;
continue;
}
j = 0;
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 | 1828 KiB | ||||
2 | Accepted | 3ms | 2024 KiB | ||||
subtask2 | 15/15 | ||||||
3 | Accepted | 3ms | 2236 KiB | ||||
4 | Accepted | 3ms | 2444 KiB | ||||
5 | Accepted | 3ms | 2652 KiB | ||||
6 | Accepted | 2ms | 2740 KiB | ||||
7 | Accepted | 19ms | 7300 KiB | ||||
8 | Accepted | 25ms | 7504 KiB | ||||
9 | Accepted | 25ms | 7208 KiB | ||||
subtask3 | 0/19 | ||||||
10 | Accepted | 3ms | 3032 KiB | ||||
11 | Wrong answer | 3ms | 3112 KiB | ||||
12 | Accepted | 2ms | 3096 KiB | ||||
13 | Accepted | 3ms | 3244 KiB | ||||
14 | Accepted | 2ms | 3224 KiB | ||||
15 | Accepted | 3ms | 3104 KiB | ||||
16 | Accepted | 2ms | 3108 KiB | ||||
subtask4 | 34/34 | ||||||
17 | Accepted | 3ms | 3196 KiB | ||||
18 | Accepted | 4ms | 3696 KiB | ||||
19 | Accepted | 4ms | 3880 KiB | ||||
20 | Accepted | 6ms | 3888 KiB | ||||
21 | Accepted | 6ms | 4044 KiB | ||||
22 | Accepted | 6ms | 4208 KiB | ||||
subtask5 | 0/32 | ||||||
23 | Wrong answer | 32ms | 11892 KiB | ||||
24 | Accepted | 48ms | 15336 KiB | ||||
25 | Accepted | 56ms | 18168 KiB | ||||
26 | Wrong answer | 43ms | 20788 KiB | ||||
27 | Accepted | 57ms | 22804 KiB | ||||
28 | Wrong answer | 68ms | 18280 KiB | ||||
29 | Wrong answer | 93ms | 42440 KiB | ||||
30 | Wrong answer | 93ms | 42384 KiB | ||||
31 | Wrong answer | 54ms | 25308 KiB | ||||
32 | Accepted | 43ms | 11728 KiB | ||||
33 | Accepted | 93ms | 33852 KiB | ||||
34 | Accepted | 93ms | 33856 KiB |