Submission #878293

#TimeUsernameProblemLanguageResultExecution timeMemory
878293ArashJafariyan Martian DNA (BOI18_dna)C++17
100 / 100
29 ms5092 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back const int N = 2e5 + 4; int n, k, r, a[N], mn[N], cnt[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k >> r; for (int i = 0; i < n; ++i) { cin >> a[i]; } for (int i = 0; i < r; ++i) { int b; cin >> b; cin >> mn[b]; } int ans = INT_MAX; int l = 0, r = 0, ok = 0; ++cnt[a[0]]; for (int i = 0; i < k; ++i) { if (cnt[i] >= mn[i]) { ++ok; } } while (l <= r) { if (ok == k) { ans = min(ans, r - l + 1); if (cnt[a[l]] == mn[a[l]]) { --ok; } --cnt[a[l]]; ++l; } else { if (r == n - 1) { break; } ++r; if (cnt[a[r]] == mn[a[r]] - 1) { ++ok; } ++cnt[a[r]]; } } if (ans == INT_MAX) { cout << "impossible"; } else { cout << ans; } 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...