Submission #1034545

#TimeUsernameProblemLanguageResultExecution timeMemory
1034545dutinmeow Martian DNA (BOI18_dna)C++17
100 / 100
69 ms4692 KiB
#include <iostream> #include <utility> #include <vector> int main() { int n, k, r; std::cin >> n >> k >> r; std::vector<int> a(n); for (int &x : a) std::cin >> x; std::vector<int> c(k, 0); for (int i = 0; i < r; i++) { int h, q; std::cin >> h >> q; c[h] = q; } int rr = n+1, bl = 0, br = -1, fn = 0; std::vector<int> f(k, 0); while (bl < n) { while (br < n-1 && fn < r) { int h = a[++br]; if (++f[h] == c[h]) fn++; } if (fn == r) rr = std::min(rr, br-bl+1); int h = a[bl++]; if (f[h]-- == c[h]) fn--; } if (rr == n+1) std::cout << "impossible\n"; else std::cout << rr << '\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...