Submission #1005961

#TimeUsernameProblemLanguageResultExecution timeMemory
1005961pudelos Martian DNA (BOI18_dna)C++17
100 / 100
111 ms9300 KiB
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for(int i=a; i<=b; ++i) #define ll long long #define sz(A) (int)(A.size()) #define pb push_back #define eb emplace_back #define V vector #define pi pair<int, int> #define f first #define s second const int inf=1e9; int res=inf; int n, k, r; V<int> A, stan, needed; int main() { cin.tie(0) -> ios_base::sync_with_stdio(0); cin >> n >> k >> r; A.resize(n+1); needed.resize(k+1); stan.resize(k+1); FOR(i, 1, n) cin >> A[i]; set<pi> secik; int co, ile; FOR(i, 1, r) { cin >> co >> ile; if(ile<=0) continue; needed[co]=ile; secik.insert({co, ile}); } // int l=1; int r=1; stan[A[1]]++; auto it = secik.find({A[1], needed[A[1]]}); if(it!=secik.end()) { pi dane = *it; dane.s--; secik.erase(it); if(dane.s!=0) secik.insert(dane); } while(!secik.empty() && r<n) { ++r; auto it = secik.find({A[r], needed[A[r]]-stan[A[r]]}); stan[A[r]]++; if(it!=secik.end()) { pi dane = *it; dane.s--; secik.erase(it); if(dane.s!=0) secik.insert(dane); } } if(!secik.empty()) { cout << "impossible\n"; return 0; } res=min(res, r); int l=1; while(l<=n) { stan[A[l]]--; while(r<n && stan[A[l]]<needed[A[l]]) { ++r; stan[A[r]]++; } if(stan[A[l]]<needed[A[l]]) break; ++l; res=min(res, r-l+1); } 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...