Submission #403984

#TimeUsernameProblemLanguageResultExecution timeMemory
403984rama_pang Martian DNA (BOI18_dna)C++17
100 / 100
43 ms4540 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int N, K, R; cin >> N >> K >> R; vector<int> A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } vector<int> B(K); for (int i = 0; i < R; i++) { int x, y; cin >> x >> y; B[x] = y; } int ans = N + 1; int bad = R; vector<int> freq(K); const auto Modify = [&](int k, int sgn) { bad -= freq[k] < B[k]; freq[k] += sgn; bad += freq[k] < B[k]; }; for (int i = 0, j = 0; i < N; i++) { Modify(A[i], +1); while (bad == 0) { Modify(A[j], -1); if (bad == 0) { j += 1; } else { Modify(A[j], +1); break; } } if (bad == 0) { ans = min(ans, i - j + 1); } } if (ans > N) { cout << "impossible\n"; } else { cout << ans << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...