Submission #798222

#TimeUsernameProblemLanguageResultExecution timeMemory
798222tch1cherin Martian DNA (BOI18_dna)C++17
100 / 100
193 ms12816 KiB
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(nullptr)->sync_with_stdio(false); int N, K, R; cin >> N >> K >> R; vector<int> D(N); for (int &v : D) { cin >> v; } vector<int> cnt(N); multiset<int> S; for (int i = 0; i < R; i++) { int B; cin >> B; cin >> cnt[B]; } for (int i = 0; i < N; i++) { S.insert(cnt[i]); } int ans = N + 1; for (int i = 0, j = 0; i < N; i++) { j = max(j, i); while (j < N && *S.rbegin() > 0) { S.erase(S.find(cnt[D[j]])); S.insert(--cnt[D[j]]); j++; } if (*S.rbegin() <= 0) { ans = min(ans, j - i); } S.erase(S.find(cnt[D[i]])); S.insert(++cnt[D[i]]); } if (ans > N) { cout << "impossible\n"; } else { cout << ans << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...