Submission #748233

#TimeUsernameProblemLanguageResultExecution timeMemory
748233JellyTheOctopus Martian DNA (BOI18_dna)C++17
0 / 100
85 ms4088 KiB
#include <bits/stdc++.h> using namespace std; int N, K, R; int main() { cin >> N >> K >> R; vector<int> arr(N); for (int i = 0; i < N; i++) { cin >> arr[i]; } vector<int> need(K, INT_MAX); for (int i = 0; i < R; i++) { int B, Q; cin >> B >> Q; need[B] = Q; } deque<int> d; vector<int> freq(K); int done = 0; int i = 0; int ans = INT_MAX; while (i < N) { while (done < R && i+1 < N) { d.push_back(i); freq[arr[i]]++; if (freq[arr[i]] == need[arr[i]]) { done++; } i++; } while (done == R) { int j = d.front(); d.pop_front(); freq[arr[j]]--; if (freq[arr[j]] == need[arr[j]]-1) { done--; ans = min(ans, i-j); break; } } i++; } if (ans == INT_MAX) { 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...