Submission #505270

#TimeUsernameProblemLanguageResultExecution timeMemory
505270wiwiho Martian DNA (BOI18_dna)C++14
100 / 100
33 ms4548 KiB
#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n, k, r; cin >> n >> k >> r; vector<int> a(n + 1); for(int i = 1; i <= n; i++) cin >> a[i]; vector<int> need(k); vector<int> cnt(k); for(int i = 0; i < r; i++){ int b, q; cin >> b >> q; need[b] = q; } int lp = 1; int ans = -1; int ok = r; for(int i = 1; i <= n; i++){ cnt[a[i]]++; if(cnt[a[i]] == need[a[i]]) ok--; while(lp < i && ok == 0 && cnt[a[lp]] > need[a[lp]]){ cnt[a[lp]]--; lp++; } if(ok != 0) continue; int len = i - lp + 1; if(ans == -1 || len < ans) ans = len; } if(ans == -1) cout << "impossible\n"; else cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...