Submission #788614

#TimeUsernameProblemLanguageResultExecution timeMemory
788614WLZ Martian DNA (BOI18_dna)C++17
100 / 100
32 ms4552 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> ii; typedef long long ll; const int INF = 1e9; const int MAXN = 2e5 + 5; const ll LINF = 1e18; const double pi = acos(-1); const double EPS = 1e-9; template <class T> using MinPQ = priority_queue<T, vector<T>, greater<T>>; template <class T> using MaxPQ = priority_queue<T>; int n, k, r; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k >> r; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<int> q(k); int numOfMatched = k - r; for (int i = 0; i < r; i++) { int b; cin >> b; cin >> q[b]; } int j = 0; vector<int> matched(k, 0); int ans = 1e9; int curLen = 0; for (int i = 0; i < n; i++) { matched[a[i]]++; ++curLen; if (matched[a[i]] == q[a[i]]) ++numOfMatched; if (numOfMatched == k) ans = min(ans, curLen); while (j <= i && numOfMatched == k) { matched[a[j]]--; if (matched[a[j]] < q[a[j]]) numOfMatched--; j++; curLen--; if (numOfMatched == k) ans = min(ans, curLen); } } 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...