86582024-01-25 00:54:20rennKutyavetélkedőcpp17Wrong answer 34/100131ms43640 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]));
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1832 KiB
2Accepted3ms2048 KiB
subtask20/15
3Accepted3ms2268 KiB
4Accepted3ms2604 KiB
5Accepted3ms2744 KiB
6Accepted3ms2960 KiB
7Wrong answer26ms7632 KiB
8Accepted27ms7840 KiB
9Accepted26ms8124 KiB
subtask30/19
10Accepted3ms3624 KiB
11Wrong answer2ms3628 KiB
12Accepted2ms3636 KiB
13Accepted3ms3728 KiB
14Accepted3ms3856 KiB
15Accepted3ms3848 KiB
16Accepted3ms3960 KiB
subtask434/34
17Accepted3ms4172 KiB
18Accepted4ms4328 KiB
19Accepted6ms4640 KiB
20Accepted6ms4900 KiB
21Accepted7ms5344 KiB
22Accepted7ms5644 KiB
subtask50/32
23Wrong answer46ms13104 KiB
24Accepted52ms16328 KiB
25Accepted54ms19224 KiB
26Wrong answer61ms22024 KiB
27Accepted59ms24348 KiB
28Wrong answer97ms19588 KiB
29Wrong answer131ms43544 KiB
30Wrong answer131ms43640 KiB
31Wrong answer79ms26524 KiB
32Accepted45ms13136 KiB
33Accepted107ms35164 KiB
34Accepted93ms35384 KiB