# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
709480 | stevancv | Martian DNA (BOI18_dna) | C++14 | 188 ms | 143160 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 <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 2e5 + 5;
const int inf = 1e9;
const int mod = 1e9 + 7;
deque<int> dq[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m, k;
cin >> n >> m >> k;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
vector<int> b(m);
for (int i = 0; i < k; i++) {
int x, y;
cin >> x >> y;
b[x] = y;
}
set<int> s;
int dobri = 0;
int ans = 1e6;
for (int i = 0; i < n; i++) {
if (b[a[i]] == 0) continue;
dq[a[i]].push_back(i);
if (dq[a[i]].size() > b[a[i]]) {
s.erase(dq[a[i]].front());
dq[a[i]].pop_front();
s.insert(dq[a[i]].front());
}
else if (dq[a[i]].size() == b[a[i]]) {
s.insert(dq[a[i]].front());
dobri += 1;
}
if (dobri == k) smin(ans, i - *s.begin() + 1);
}
if (ans == 1e6) cout << "impossible" << en;
else cout << ans << en;
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... |