Submission #396737

#TimeUsernameProblemLanguageResultExecution timeMemory
396737danielcm585 Martian DNA (BOI18_dna)C++14
100 / 100
63 ms2460 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second typedef long long ll; typedef pair<int,int> ii; const int N = 2e5; int n, k, r; int a[N+2], cnt[N+2], need[N+2]; bool can(int mid) { memset(cnt,0,sizeof(cnt)); int get = 0; for (int i = 1; i <= n; i++) { cnt[a[i]]++; get += (need[a[i]] && cnt[a[i]] == need[a[i]]); if (i-mid >= 1) { get -= (need[a[i-mid]] && cnt[a[i-mid]] == need[a[i-mid]]); cnt[a[i-mid]]--; } if (i >= mid && get == r) return 1; } return 0; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k >> r; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= r; i++) { int b, q; cin >> b >> q; need[b] = q; } int ans = -1; for (int l = 1, r = n; l <= r; ) { int mid = (l+r)/2; if (can(mid)) { ans = mid; r = mid-1; } else l = mid+1; } if (ans == -1) cout << "impossible\n"; else cout << ans << '\n'; 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...