Submission #647190

#TimeUsernameProblemLanguageResultExecution timeMemory
647190tvladm2009 Martian DNA (BOI18_dna)C++14
100 / 100
45 ms4556 KiB
#include <bits/stdc++.h> using ll = long long; int const nmax = 200000; int v[1 + nmax], mn[1 + nmax], fr[1 + nmax]; int main() { std::ios_base::sync_with_stdio(0); std::cin.tie(0); int n, k, r; std::cin >> n >> k >> r; for(int i = 1;i <= n; i++) std::cin >> v[i]; for(int i = 1;i <= r; i++) { int x, y; std::cin >> x >> y; mn[x] = y; } int j = 1, cnt = 0; while(j <= n && cnt != r) { fr[v[j]]++; if(fr[v[j]] == mn[v[j]]) cnt++; j++; } if(cnt != r) { std::cout << "impossible"; return 0; } int ans = j - 1; for(int i = 2;i <= n; i++) { fr[v[i - 1]]--; if(fr[v[i - 1]] < mn[v[i - 1]]) cnt--; while(j <= n && cnt != r) { fr[v[j]]++; if(fr[v[j]] == mn[v[j]]) cnt++; j++; } if(cnt != r) break; ans = std::min(ans, j - i); } std::cout << ans; 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...