Submission #642579

#TimeUsernameProblemLanguageResultExecution timeMemory
642579andreast12 Martian DNA (BOI18_dna)C++17
0 / 100
44 ms4020 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define fi first #define se second const int mod=998244353, maxn=2e5+5; int n, k, r, a[maxn], tipe, butuh[maxn], ki, ka, mid, res, unik, cukup, cnt[maxn], x; bool penting[maxn], bisa; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k >> r; for(int i=1; i<=n; i++) cin >> a[i]; for(int i=1; i<=r; i++) { cin >> tipe >> x; penting[tipe]=true; butuh[tipe]=x; } ki=1, ka=n, res=-1; while(ki<=ka) { mid=(ki+ka)/2, bisa=false, unik=cukup=0; for(int i=0; i<=n; i++) cnt[i]=0; for(int i=1; i<=n; i++) { if(!cnt[a[i]]) unik++; cnt[a[i]]++; if(cnt[a[i]]==butuh[a[i]]&&penting[a[i]]) cukup++; if(i>mid) { cnt[a[i-mid]]--; if(!cnt[a[i-mid]]) unik--; if(cnt[a[i-mid]]==butuh[a[i-mid]]-1&&penting[a[i-mid]]) cukup--; } if(unik>=k&&cukup>=r) bisa=true; } if(bisa) { res=mid; ka=mid-1; } else ki=mid+1; } if(res==-1) cout << "impossible"; else cout << res; cout << '\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...