제출 #396736

#제출 시각아이디문제언어결과실행 시간메모리
396736danielcm585 Martian DNA (BOI18_dna)C++14
0 / 100
38 ms2432 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; const int INF = 1e9; int n, k, r; int a[N+2], cnt[N+2], need[N+2]; 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 = INF, get = 0; for (int i = 1, j = 1; j <= n; i++) { while (j <= n && get < r) { cnt[a[j]]++; get += (need[a[j]] && cnt[a[j]] == need[a[j]]); j++; } // cout << i << " -> " << j << '\n'; if (get == r) ans = min(ans,j-i); get -= (need[a[i]] && cnt[a[i]] == need[a[i]]); cnt[a[i]]--; } if (ans == INF) 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...