Submission #596807

#TimeUsernameProblemLanguageResultExecution timeMemory
596807penguinhacker Martian DNA (BOI18_dna)C++17
100 / 100
372 ms12528 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array const int mxN=2e5; int n, k, r, a[mxN], cnt[mxN]; set<ar<int, 2>> s; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k >> r; for (int i=0; i<n; ++i) cin >> a[i]; while(r--) { int x, y; cin >> x >> y; cnt[x]=y; s.insert({y, x}); } for (int i=0; i<k; ++i) if (!cnt[i]) s.insert({0, i}); int ans=69696969; for (int l=0, r=0; r<n; ++r) { s.erase({cnt[a[r]], a[r]}); s.insert({--cnt[a[r]], a[r]}); if ((*s.rbegin())[0]>0) continue; while(cnt[a[l]]<0) { s.erase({cnt[a[l]], a[l]}); s.insert({++cnt[a[l]], a[l++]}); } ans=min(ans, r-l+1); } if (ans==69696969) { cout << "impossible"; return 0; } cout << ans; 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...