Submission #653681

#TimeUsernameProblemLanguageResultExecution timeMemory
653681veiga Martian DNA (BOI18_dna)C++17
100 / 100
37 ms7116 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define pb push_back #define F first #define S second #define endl "\n" const int INF = 1e9+10; const int MOD = 1e9+7; int n, k, t; int v[200020]; int need[200020]; int32_t main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> k >> t; for(int i = 0; i < n; i++) { cin >> v[i]; } for(int i = 0; i < t; i++) { int a, b; cin >> a >> b; need[a] = b; } int l = 0, r = 0, ok = 0; int cnt[200020] = {}; bool okay[200020] = {}; cnt[v[r]]++; int resp = INF; if(need[v[r]] != 0 and cnt[v[r]] >= need[v[r]]) { ok++; okay[v[r]] = true; } while(r < n) { // cout << l << " " << r << endl; // cout << v[l] << " " << v[r] << endl; // cout << ok << endl << endl; if(ok == t) { resp = min(resp, r - l + 1); cnt[v[l]]--; if(need[v[l]] and cnt[v[l]] < need[v[l]] and okay[v[l]]) { ok--; okay[v[l]] = false; } l++; } else { r++; cnt[v[r]]++; if(need[v[r]] and cnt[v[r]] >= need[v[r]] and !okay[v[r]]) { ok++; okay[v[r]] = true; } } } if(resp == INF) cout << "impossible" << endl; else cout << resp << endl; 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...