# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
547973 | Jarif_Rahman | Martian DNA (BOI18_dna) | C++17 | 147 ms | 137676 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 pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k, r; cin >> n >> k >> r;
vector<int> v(n);
for(int &x: v) cin >> x;
vector<queue<int>> sth(k);
vector<int> req(k, 0);
for(int i = 0; i < r; i++){
int b, q; cin >> b >> q;
req[b] = q;
}
int tbo = r;
set<int> ss;
int ans = 1e9;
for(int i = 0; i < n; i++){
if(sth[v[i]].size() < req[v[i]]){
sth[v[i]].push(i);
ss.insert(i);
if(sth[v[i]].size() == req[v[i]]) tbo--;
}
else if(req[v[i]] != 0){
sth[v[i]].push(i);
ss.insert(i);
ss.erase(sth[v[i]].front());
sth[v[i]].pop();
}
if(tbo == 0) ans = min(ans, i-*ss.begin()+1);
}
if(ans > n) cout << "impossible\n";
else cout << ans << "\n";
}
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... |