Submission #731671

#TimeUsernameProblemLanguageResultExecution timeMemory
731671NintsiChkhaidze Martian DNA (BOI18_dna)C++17
100 / 100
31 ms2664 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5,inf=1e9; int a[N],mn[N],cnt[N]; signed main (){ ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL); int n,k,R; cin>>n>>k>>R; for (int i = 1; i <= n; i++){ cin>>a[i]; } for (int i = 0; i < k; i++) mn[i] = inf; for (int i = 1; i <= R; i++){ int x,y; cin>>x>>y; mn[x] = y; } int C = R,r = 0,ans=inf; for (int i = 1; i <= n; i++){ while (C > 0 && r + 1 <= n){ ++r; cnt[a[r]]++; if (cnt[a[r]] - 1 < mn[a[r]] && cnt[a[r]] == mn[a[r]]) C--; } if (C == 0) ans=min(ans,r - i + 1); cnt[a[i]]--; if (cnt[a[i]] + 1 == mn[a[i]] && cnt[a[i]] < mn[a[i]]) ++C; } if(ans==inf) cout<<"impossible"; else cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...