Submission #62747

#TimeUsernameProblemLanguageResultExecution timeMemory
62747MatheusLealVGenetics (BOI18_genetics)C++17
0 / 100
5 ms1144 KiB
#include <bits/stdc++.h> #define N 200050 using namespace std; int n, r, k, qtd[N], v[N], T[N], ans = 2000000000; int esq, dir; int main() { ios::sync_with_stdio(false); cin.tie(0); cin>>n>>k>>r; for(int i = 1; i <= n; i++) cin>>v[i]; for(int i = 0; i < r; i++) { int x, t; cin>>x>>t; qtd[x] = t; } int ini = 1, fim = n, mid, best = -1; while(fim >= ini) { bool nop = 0; mid = (ini + fim)/2; memset(T, 0, sizeof T); for(int i = 1; i <= mid; i++) T[v[i]] ++; for(int i = 0; i < k; i++) if(T[i] < qtd[i]) nop = 1; if(nop) ini = mid + 1; else fim = mid - 1, best = mid; } if(best == -1) { cout<<"impossible\n"; return 0; } esq = 1, dir = best, ans = best; memset(T, 0, sizeof T); for(int i = 1; i <= best; i++) T[v[i]] ++; for(; dir <= n; dir++) { while(T[v[esq]] - 1 >= qtd[v[esq]] && esq <= dir) T[v[esq]] --, esq ++; ans = min(ans, (dir - esq + 1)); T[v[dir + 1]] ++; } if(ans < 2000000000 && best != -1)cout<<ans<<'\n'; else cout<<"impossible\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...