Submission #728007

#TimeUsernameProblemLanguageResultExecution timeMemory
728007WonderfulWhale Martian DNA (BOI18_dna)C++17
100 / 100
46 ms8128 KiB
#include<bits/stdc++.h> using namespace std; #define int int64_t #define pb push_back #define st first #define nd second #define pii pair<int, int> #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() const int MAXN = 200009; int cnt[MAXN]; int sum[MAXN]; int cur[MAXN]; int tab[MAXN]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k, r; cin >> n >> k >> r; for(int i=0;i<n;i++) { cin >> tab[i]; sum[tab[i]]++; } for(int i=0;i<r;i++) { int a, b; cin >> a >> b; cnt[a] = b; if(sum[a]<b) { cout << "impossible\n"; return 0; } } int R = -1; int bad_cnt = r; int ans = 1e9; for(int L=0;L<n;L++) { while(R+1<n && bad_cnt) { R++; cur[tab[R]]++; if(cur[tab[R]]==cnt[tab[R]]) { bad_cnt--; } } if(bad_cnt==0) { ans = min(ans, R-L+1); } cur[tab[L]]--; if(cur[tab[L]]==cnt[tab[L]]-1) { bad_cnt++; } } cout << ans << "\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...