# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
789460 | Trisanu_Das | Martian DNA (BOI18_dna) | C++17 | 0 ms | 0 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>
using namespace std;
int x;
int main(){
int n, k, cnt;
int a[n + 1], b[n + 1], ccnt[n + 1]; memset(cnt, 0, sizeof(ccnt));
for(int i = 1; i < n + 1; i++) cin >> a[i];
for(int i = 1; i < cnt + 1; i++){
cin >> x; cin >> b[x];
}
int l = 1, r = 0, ans = INT_MAX;
while(r < n + 1){
if(cnt){
r++; ccnt[a[r]]++;
if(ccnt[a[r]] == b[a[r]]) cnt--;
}else{
ans = min(ans, r - l + 1);
if(ccnt[a[l]] == b[a[l]]) cnt++;
ccnt[a[l]]--; l++;
}
}
if(ans == INT_MAX) cout << "impossible\n";
else cout << ans << '\n';
}