Submission #676782

#TimeUsernameProblemLanguageResultExecution timeMemory
676782Cyanmond Martian DNA (BOI18_dna)C++17
0 / 100
209 ms31344 KiB
#include <bits/stdc++.h> int main() { int N, K, R; std::cin >> N >> K >> R; std::vector<int> D(N); for (auto &e : D) { std::cin >> e; } std::vector<std::vector<int>> index_list(K); for (int i = 0; i < N; ++i) { index_list[D[i]].push_back(i); } std::vector<std::vector<std::pair<int, bool>>> events(N + 1); while (R--) { int B, Q; std::cin >> B >> Q; const auto &list = index_list[B]; if ((int)list.size() < Q) { events[0].push_back({3 * N, true}); break; } events[0].push_back({list[Q - 1], true}); for (int i = 0; i < (int)list.size() - Q; ++i) { events[list[i] + 1].push_back({list[i + Q - 1], false}); events[list[i] + 1].push_back({list[i + Q], true}); } events[list[(int)list.size() - Q] + 1].push_back({3 * N, true}); } std::multiset<int> mls; int answer = N; for (int i = 0; i < N; ++i) { for (const auto &[v, b] : events[i]) { if (b) { mls.insert(v); } else { mls.erase(mls.find(v)); } } answer = std::min(answer, *mls.rbegin() - i + 1); } if (answer == N) { std::cout << "impossible" << std::endl; } else { std::cout << answer << std::endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...