제출 #1124451

#제출 시각아이디문제언어결과실행 시간메모리
1124451henriess Martian DNA (BOI18_dna)C++20
0 / 100
475 ms19432 KiB
#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n,k,r;cin >> n >> k >> r; vector<long long> v(n); set<long long> s; map<long long,long long> m; for(int i = 0;i<n;i++){ cin >> v[i]; } for(int i = 0;i<r;i++){ long long gene,required; cin >> gene >> required; m[gene] = required; } long long left = 0; long long current = 0; long long ans = LLONG_MAX; long long completed = 0; map<long long, long long> track; for(int i = 0;i<n;i++){ if (track[v[i]] == 0){ track[v[i]] = 1; } else{ track[v[i]] += 1; } if (m.find(v[i]) != m.end() && track[v[i]] >= m[v[i]] ){ completed += 1; } while (completed >= r){ ans = min(ans,i - left+ 1); track[v[left]]--; if (m.find(v[left]) != m.end() && track[v[left]] <m[v[left]]){ completed--; } left++; } } if (ans == LLONG_MAX){ cout << "impossible"; return 0; } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...