제출 #1123568

#제출 시각아이디문제언어결과실행 시간메모리
1123568jjjwong Martian DNA (BOI18_dna)C++20
100 / 100
32 ms3012 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int N, K, R; cin >> N >> K >> R; vector<int> A; int req[K], curr[K]; int ans = 0; fill(req, req+K, 0); fill(curr, curr+K, 0); for (int i=0; i<N; ++i) { int n; cin >> n; A.emplace_back(n); } for (int i=0; i<R; ++i) { int n, amt; cin >> n >> amt; req[n] = amt; } int req_met = 0; if (R == 0) { cout << 1; return 0; } int l = 0, r = 0; while (l < N) { if (req_met < R && r<N) { curr[A[r]]++; if (req[A[r]] > 0 && curr[A[r]] == req[A[r]]) req_met++; r++; } else { if (req_met >= R) { if (ans == 0) ans = r - l; else ans = min(ans, r-l); } curr[A[l]]--; if (req[A[l]] > 0 && curr[A[l]] < req[A[l]]) req_met--; l++; } } if (ans != 0) cout << ans; else cout << "impossible"; 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...