Submission #577058

#TimeUsernameProblemLanguageResultExecution timeMemory
577058Pietra Martian DNA (BOI18_dna)C++14
40 / 100
37 ms3156 KiB
#include<bits/stdc++.h> using namespace std ; const int maxn = 1e5 + 5 ; int n, k, r, freq[maxn], v[maxn], qtd[maxn] ; bool check(int x){ // cout << x << ":\n" ; for(int i = 0 ; i <= k ; i++) freq[i] = 0 ; int ct = 0 ; for(int i = 1 ; i <= x ; i++){ freq[v[i]]++ ; if(freq[v[i]] == qtd[v[i]]) ct++ ; } if(r == ct) return 1 ; for(int i = x + 1 ; i <= n ; i++){ if(freq[v[i-x]] == qtd[v[i-x]]) ct-- ; freq[v[i-x]]-- ; freq[v[i]]++ ; if(freq[v[i]] == qtd[v[i]]) ct++ ; // cout << "pos " << i << " " << ct << " " ; if(r == ct) return 1 ; } // cout << "\n" << ct << "\n" ; if(r == ct) return 1 ; return 0 ; } int main(){ ios_base::sync_with_stdio(false) ; cin.tie(NULL) ; cin >> n >> k >> r ; for(int i = 1 ; i <= n ; i++) cin >> v[i] ; for(int i = 1 ; i <= r ; i++){ int v, f ; cin >> v >> f ; qtd[v] = f ; } int ini = 1, fim = n, mid, best = -1 ; while(ini <= fim){ mid = (ini + fim)>>1 ; if(check(mid)) best = mid, fim = mid - 1 ; else ini = mid + 1 ; } if(best == -1) cout << "impossible\n" ; else cout << best << "\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...