Submission #731667

#TimeUsernameProblemLanguageResultExecution timeMemory
731667NintsiChkhaidze Martian DNA (BOI18_dna)C++17
0 / 100
35 ms3924 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 = 1; 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 = 1,ans=inf; cnt[a[1]]++; if (cnt[a[1]] >= mn[a[1]]) --C; 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...