Submission #530341

#TimeUsernameProblemLanguageResultExecution timeMemory
530341fatemetmhr Martian DNA (BOI18_dna)C++17
100 / 100
35 ms3824 KiB
#include <bits/stdc++.h> using namespace std; const int maxn5 = 3e5 + 10; int a[maxn5], req[maxn5]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k, r; cin >> n >> k >> r; for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < r; i++){ int a, b; cin >> a >> b; req[a] = b; } int id = 0; req[a[0]]--; int rem = r, ans = n + 10; if(req[a[0]] == 0) rem--; for(int i = 0; i < n; i++){ while(rem && id < n - 1){ id++; req[a[id]]--; if(req[a[id]] == 0) rem--; } if(rem == 0) ans = min(ans, id - i + 1); req[a[i]]++; if(req[a[i]] == 1) rem++; if(id == i){ id++; req[a[id]]--; if(req[a[id]] == 0) rem--; } } if(ans > n) cout << "impossible" << endl; else cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...