93592024-02-21 09:33:47szilSzínes szobák (50 pont)cpp17Wrong answer 46/5037ms18432 KiB
#include <bits/stdc++.h>

using ll = long long;
using namespace std;

const int MAXN = 100'002;

int c[MAXN], n, k, m;
vector<pair<int, int>> v;

bool f(int pos, int border) {
    for (auto [a, b] : v) {
        if (c[pos] == a) pos += b;
        if (pos <= border && border == 0) return true;
        if (pos >= border && border == n+1) return true;
    }
    return false;
}

void solve() {
    cin >> n >> k >> m;
    v.resize(m);
    for (int i = 1; i <= n; i++) cin >> c[i];
    for (auto &[a, b] : v) {
        cin >> a >> b;
    }
    int ans = 0;
    {
        int lo = 0, hi = n;
        while (lo < hi) {
            int mid = (lo + hi + 1) / 2;
            if (f(mid, 0)) lo = mid;
            else hi = mid - 1;
        }
        ans += lo;
    }
    {
        int lo = 0, hi = n;
        while (lo < hi) {
            int mid = (lo + hi) / 2;
            if (f(mid, n+1)) hi = mid;
            else lo = mid + 1;
        }
        ans += n-lo+1;
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base46/50
1Accepted0/03ms1892 KiB
2Accepted0/037ms5652 KiB
3Accepted1/13ms3664 KiB
4Wrong answer0/13ms3748 KiB
5Accepted1/13ms3992 KiB
6Wrong answer0/13ms4208 KiB
7Accepted1/13ms4180 KiB
8Wrong answer0/13ms4432 KiB
9Accepted1/13ms4400 KiB
10Wrong answer0/13ms4412 KiB
11Accepted1/13ms4428 KiB
12Accepted1/13ms4440 KiB
13Accepted1/14ms4780 KiB
14Accepted1/14ms4704 KiB
15Accepted1/14ms4884 KiB
16Accepted1/16ms5332 KiB
17Accepted1/16ms5324 KiB
18Accepted1/16ms5508 KiB
19Accepted1/123ms7192 KiB
20Accepted1/137ms9268 KiB
21Accepted1/127ms9432 KiB
22Accepted1/129ms10320 KiB
23Accepted1/135ms11400 KiB
24Accepted1/137ms12832 KiB
25Accepted1/137ms13808 KiB
26Accepted1/137ms14636 KiB
27Accepted3/335ms15160 KiB
28Accepted3/335ms15664 KiB
29Accepted3/335ms16192 KiB
30Accepted3/335ms16744 KiB
31Accepted3/335ms17308 KiB
32Accepted3/335ms17868 KiB
33Accepted4/419ms17144 KiB
34Accepted4/432ms18432 KiB