Submission #1013787

#TimeUsernameProblemLanguageResultExecution timeMemory
1013787vjudge1 Martian DNA (BOI18_dna)C++17
100 / 100
86 ms7200 KiB
#include<bits/stdc++.h> using namespace std; #ifdef ONPC #include"debug.h" #else #define debug(...) 42 #endif #define endl '\n' #define ll long long #define pii pair<int,int> #define F first #define S second #define pb push_back #define sz(a) (int)a.size() #define all(a) a.begin(),a.end() template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } const int mod = 1e9 + 7; const int MAXN = 1e6 + 15; const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3f; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n, k, r; cin >> n >> k >> r; vector<int> a(n), frq(k), needs(k); for (int i = 0; i < n; i++){ cin >> a[i]; } set<int> active; for (int i = 0; i < r; i++){ int u, v; cin >> u >> v; needs[u] = v; active.insert(u); } int p1 = 0, p2 = 0; int ans = inf; while (p1 < n){ while (p2 < n && sz(active)){ frq[a[p2]]++; if (frq[a[p2]] == needs[a[p2]]) active.erase(a[p2]); p2++; } if (sz(active) == 0){ ckmin(ans, p2 - p1); } if (frq[a[p1]] == needs[a[p1]]){ active.insert(a[p1]); } frq[a[p1]]--; p1++; } if (ans != inf) cout << ans << endl; else cout << "impossible\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...