Submission #283265

#TimeUsernameProblemLanguageResultExecution timeMemory
283265AlexLuchianov Martian DNA (BOI18_dna)C++14
100 / 100
176 ms19832 KiB
#include <iostream> #include <vector> #include <cassert> #include <cmath> #include <set> using ll = long long; #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #define MAX(a, b) (((a) < (b)) ? (b) : (a)) int const nmax = 200000; std::vector<int> g[1 + nmax]; int ptr[1 + nmax], v[1 + nmax]; int cond[1 + nmax]; int main() { std::ios::sync_with_stdio(0); std::cin.tie(0); int n, k, q; std::cin >> n >> k >> q; for(int i = 1;i <= n; i++) { std::cin >> v[i]; g[v[i]].push_back(i); } std::multiset<int> pq; for(int i = 1;i <= q;i++) { int val, cant; std::cin >> val >> cant; pq.insert(0); cond[val] = cant; if(g[val].size() < cant) { std::cout << "impossible"; return 0; } } int result = n + 1; for(int i = 1;i <= n; i++) { ptr[v[i]]++; if(0 == cond[v[i]]) continue; if(ptr[v[i]] == cond[v[i]]) { pq.erase(pq.find(0)); pq.insert(g[v[i]][0]); } else if(cond[v[i]] < ptr[v[i]]) { pq.insert(g[v[i]][ptr[v[i]] - cond[v[i]] ]); pq.erase(pq.find(g[v[i]][ptr[v[i]] - cond[v[i]] - 1]) ); } if(0 < *pq.begin()) result = std::min(result, i - *pq.begin() + 1); } if(result <= n) std::cout << result; else std::cout << "impossible"; return 0; }

Compilation message (stderr)

dna.cpp: In function 'int main()':
dna.cpp:33:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   33 |     if(g[val].size() < cant) {
      |        ~~~~~~~~~~~~~~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...