Submission #891156

#TimeUsernameProblemLanguageResultExecution timeMemory
891156Dec0Dedd Martian DNA (BOI18_dna)C++14
100 / 100
29 ms2776 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; const int N = 2e5+10; int a[N], b[N], cnt[N], cc=0, n, k, r; void add(int x) { ++cnt[x]; if (cnt[x] == b[x]) ++cc; } void rem(int x) { --cnt[x]; if (cnt[x] == b[x]-1) --cc; } void solve() { cin>>n>>k>>r; for (int i=1; i<=n; ++i) cin>>a[i], ++a[i]; for (int i=1; i<=r; ++i) { int k, x; cin>>k>>x; ++k; b[k]=x; } for (int i=1; i<=k; ++i) { if (b[i] == 0) ++cc; } int ans=n+1, r=1; while (r <= n && cc < k) add(a[r++]); assert(cc <= k); if (cc < k) { cout<<"impossible\n"; return; } ans=r-1; for (int l=1; l<=n; ++l) { if (cc == k) ans=min(ans, r-l); rem(a[l]); while (r <= n && cc < k) add(a[r++]); } cout<<ans<<"\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int t=1; while (t--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...