# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
283265 | AlexLuchianov | Martian DNA (BOI18_dna) | C++14 | 176 ms | 19832 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |