Submission #860968

#TimeUsernameProblemLanguageResultExecution timeMemory
860968vjudge1 Martian DNA (BOI18_dna)C++17
100 / 100
218 ms15416 KiB
#include <iostream> #include <vector> #include <map> #include <climits> #define int long long using namespace std; signed main() { int n, k, r, res = LLONG_MAX, ri = -1; bool ok; map<int,int> c; cin >> n >> k >> r; vector<int> a(n), sum(r); vector<pair<int,int>> b(r); for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < r; i++) { cin >> b[i].first >> b[i].second; c[b[i].first] = i+1; } //find start while(true) { if(ri == n-1) { cout << "impossible\n"; return 0; } ri++; if(c[a[ri]]) { sum[c[a[ri]]-1]++; ok = true; for(int i = 0; i < r; i++) { if(sum[i] < b[i].second) { ok = false; break; } } if(ok) break; } } //start res = ri+1; for(int i = 0; i < n; i++) { if(c[a[i]]) { sum[c[a[i]]-1]--; ok = true; while(sum[c[a[i]]-1] < b[c[a[i]]-1].second) { if(ri == n-1) { ok = false; break; } ri++; if(c[a[ri]]) sum[c[a[ri]]-1]++; } if(!ok) break; } res = min(res, ri-i); } cout << res << "\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...