Submission #576291

#TimeUsernameProblemLanguageResultExecution timeMemory
576291mmonteiro Martian DNA (BOI18_dna)C++17
100 / 100
121 ms4520 KiB
#include <iostream> #include <vector> #include <utility> #include <algorithm> #include <iomanip> int main(){ int n, k, r; std::cin >> n >> k >> r; std::vector<int> nucleobase(n); std::vector<int> frequency(k); for(int i = 0; i < n; ++i) { std::cin >> nucleobase[i]; } for(int i = 0; i < r; ++i) { int x, f; std::cin >> x >> f; frequency[x] += f; } auto add = [&](int x, std::vector<int> &frequency_aux, int &qtd_ok) { frequency_aux[x]++; if(frequency_aux[x] == frequency[x] and frequency[x] > 0) { qtd_ok++; } }; auto sub = [&](int x, std::vector<int> &frequency_aux, int &qtd_ok) { if(frequency_aux[x] == frequency[x] and frequency[x] > 0) { qtd_ok--; } frequency_aux[x]--; }; auto check = [&](int window_size) { std::vector<int> frequency_aux(k); int qtd_ok = 0; for(int i = 0; i < window_size; ++i) { add(nucleobase[i], frequency_aux, qtd_ok); } if(qtd_ok == r) { return true; } for(int i = window_size; i < n; ++i) { sub(nucleobase[i - window_size], frequency_aux, qtd_ok); add(nucleobase[i], frequency_aux, qtd_ok); if(qtd_ok == r) { return true; } } return false; }; int lo = 0, hi = n, ans = -1; while(lo <= hi) { int middle = (lo + hi) / 2; if(check(middle)) { hi = middle - 1; ans = middle; } else { lo = middle + 1; } } if(ans == -1) { std::cout << "impossible\n"; } else { std::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...