87822024-01-30 00:41:57rennKutyavetélkedőcpp17Runtime error 0/10039ms33340 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);
    cout.tie(0);
    ios::sync_with_stdio(0);

    int n, k, m, a, b;
    cin >> n >> k;

    vector<int> feladatok(n+2, -1), legjobb(n+2, -1);
    vector<unordered_set<int>> szabalyok(k+1);
    cin >> m;

    while(m--) {
        cin >> a >> b;
        a--; b--;
        if(a == k || b == k) continue;
        szabalyok[a].insert(b);
    }

    legjobb[0] = (feladatok[0]-1) == k ? -1 : 1;
    legjobb[1] = (feladatok[1]-1) == k ? -1 : 1;
    for(int i = 0, j = 0; i < n; i++) {
        if(j == 2) break;
        if(legjobb[i] == -1){
            j++;
            continue;
        }
        j = 0;
        if(cnt(szabalyok[feladatok[i]-1], feladatok[i+1]-1))
            legjobb[i+1] = max(legjobb[i+1], legjobb[i]+1);
        if(cnt(szabalyok[feladatok[i]-1], feladatok[i+2]-1))
            legjobb[i+2] = max(legjobb[i+2], legjobb[i]+1);
    }

    cout << max(0, max(legjobb[n-1], legjobb[n-2]));
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Runtime error3ms1924 KiB
2Runtime error3ms2192 KiB
subtask20/15
3Runtime error3ms2408 KiB
4Runtime error3ms2480 KiB
5Runtime error3ms2388 KiB
6Runtime error3ms2644 KiB
7Runtime error4ms6092 KiB
8Runtime error4ms6456 KiB
9Runtime error4ms6452 KiB
subtask30/19
10Runtime error3ms3304 KiB
11Runtime error3ms3424 KiB
12Runtime error3ms3232 KiB
13Runtime error3ms3236 KiB
14Runtime error3ms3488 KiB
15Runtime error3ms3704 KiB
16Runtime error3ms3808 KiB
subtask40/34
17Runtime error3ms4004 KiB
18Runtime error3ms4076 KiB
19Runtime error3ms4248 KiB
20Runtime error3ms4200 KiB
21Runtime error3ms4356 KiB
22Runtime error3ms4372 KiB
subtask50/32
23Runtime error4ms6756 KiB
24Runtime error7ms9320 KiB
25Runtime error13ms13212 KiB
26Runtime error13ms14032 KiB
27Runtime error17ms17488 KiB
28Runtime error4ms8640 KiB
29Runtime error39ms33340 KiB
30Runtime error13ms22148 KiB
31Runtime error23ms19820 KiB
32Runtime error4ms8708 KiB
33Runtime error7ms18756 KiB
34Runtime error7ms18832 KiB