Submission #1093847

#TimeUsernameProblemLanguageResultExecution timeMemory
1093847josiftepe Martian DNA (BOI18_dna)C++14
100 / 100
63 ms3920 KiB
#include <iostream> #include <vector> #include <queue> using namespace std; int main() { int n, k, m; cin >> n >> k >> m; vector<int> v(n); for(int i = 0; i < n; i++) { cin >> v[i]; } vector<int> req(k + 1, 0); for(int i = 0; i < m; i++) { int a, b; cin >> a >> b; req[a] = b; } int j = 0; int cnt = m; int res = 2e9; for(int i = 0; i < n; i++) { while(cnt > 0 and j < n) { req[v[j]]--; if(req[v[j]] == 0) { cnt--; } j++; } if(cnt == 0) { res = min(res, j - i); } req[v[i]]++; if(req[v[i]] > 0) { cnt++; } } if(res == 2e9) { cout << "impossible" << endl; } else { cout << res << endl; } 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...