53462023-04-26 10:11:23Valaki2Színes szobák (50 pont)cpp14Wrong answer 4/5037ms25320 KiB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second

const int maxn = 1e5;

int n, k, q;
int color[1 + maxn + 1];
vector<pii > steps;

bool stays(int idx, bool dir) {
    for(pii s : steps) {
        if(color[idx] == s.fi) {
            idx += s.se;
        }
        if((idx > n) ^ dir) {
            return true; // wrong direction
        }
        if((idx < 1) ^ dir) {
            return false; // correct way
        }
    }
    return true; // actually stays
}

void solve() {
    cin >> n >> k >> q;
    for(int i = 1; i <= n; i++) {
        cin >> color[i];
    }
    for(int i = 1; i <= q; i++) {
        int a, b;
        cin >> a >> b;
        steps.pb(mp(a, b));
    }
    int l = 0, r = n + 1;
    while(l < r - 1) {
        int mid = (l + r) / 2;
        if(stays(mid, false)) {
            r = mid;
        } else {
            l = mid;
        }
    }
    int ans = 0;
    ans += l;
    l = 0, r = n + 1;
    while(l < r - 1) {
        int mid = (l + r) / 2;
        if(stays(mid, true)) {
            l = mid;
        } else {
            r = mid;
        }
    }
    ans += n - l;
    cout << ans << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base4/50
1Accepted0/03ms1892 KiB
2Wrong answer0/037ms6340 KiB
3Wrong answer0/13ms3776 KiB
4Accepted1/13ms3736 KiB
5Wrong answer0/13ms3740 KiB
6Accepted1/13ms4008 KiB
7Wrong answer0/13ms4252 KiB
8Accepted1/13ms4484 KiB
9Wrong answer0/13ms4724 KiB
10Accepted1/13ms5068 KiB
11Wrong answer0/13ms5204 KiB
12Wrong answer0/13ms5216 KiB
13Wrong answer0/14ms5600 KiB
14Wrong answer0/14ms5588 KiB
15Wrong answer0/14ms5872 KiB
16Wrong answer0/14ms6240 KiB
17Wrong answer0/16ms6404 KiB
18Wrong answer0/16ms6664 KiB
19Wrong answer0/121ms9136 KiB
20Wrong answer0/135ms11064 KiB
21Wrong answer0/126ms11344 KiB
22Wrong answer0/128ms13248 KiB
23Wrong answer0/134ms14608 KiB
24Wrong answer0/135ms15716 KiB
25Wrong answer0/135ms16904 KiB
26Wrong answer0/135ms18060 KiB
27Wrong answer0/335ms19096 KiB
28Wrong answer0/335ms20100 KiB
29Wrong answer0/335ms21104 KiB
30Wrong answer0/335ms22300 KiB
31Wrong answer0/334ms23552 KiB
32Wrong answer0/335ms24516 KiB
33Wrong answer0/417ms23652 KiB
34Wrong answer0/429ms25320 KiB