Submission #643401

#TimeUsernameProblemLanguageResultExecution timeMemory
643401andecaandeci Martian DNA (BOI18_dna)C++17
100 / 100
28 ms2772 KiB
#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k, r; cin >> n >> k >> r; vector<int>a(n + 1), req(n + 1), freq(n + 1); for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i <= r; i++){ int x, y; cin >> x >> y; req[x] = y; } int ans = 1e9; int left = 1, right = 0; int ok = 0; while(left <= n && right <= n){ while(right + 1 <= n && ok != r){ freq[a[right + 1]]++; if(freq[a[right + 1]] == req[a[right + 1]]) ok++; right++; } if(ok != r) break; ans = min(ans, right - left + 1); freq[a[left]]--; if(freq[a[left]] < req[a[left]]) ok--; left++; } if(ans == 1e9) 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...