Submission #1111270

#TimeUsernameProblemLanguageResultExecution timeMemory
1111270ShadowShark Martian DNA (BOI18_dna)C++17
100 / 100
25 ms4680 KiB
#include <bits/stdc++.h>
using namespace std;

const int maxN = 2e5 + 5;
int D[maxN], req[maxN], cnt[maxN];

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n, k, q;
    cin >> n >> k >> q;

    for (int i = 1; i <= n; i++)
        cin >> D[i];

    for (int i = 1; i <= q; i++) {
        int x, y;
        cin >> x >> y;

        req[x] = y;
    }

    int satisfied = 0;
    for (int i = 0; i < k; i++)
        if (cnt[i] >= req[i]) satisfied++;

    int R = 0, ans = n + 1;
    for (int L = 1; L <= n; L++) {
        while (R <= n && satisfied != k) {
            R++; if (R > n) break;
            cnt[D[R]]++; if (cnt[D[R]] == req[D[R]]) satisfied++;
        }

        if (R > n) break; ans = min(ans, R - L + 1);
        if (cnt[D[L]] == req[D[L]]) satisfied--;
        cnt[D[L]]--;
    }

    if (ans == n + 1) cout << "impossible";
        else cout << ans;
    return 0;
}

Compilation message (stderr)

dna.cpp: In function 'int main()':
dna.cpp:34:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   34 |         if (R > n) break; ans = min(ans, R - L + 1);
      |         ^~
dna.cpp:34:27: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   34 |         if (R > n) break; ans = min(ans, R - L + 1);
      |                           ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...