Submission #759441

#TimeUsernameProblemLanguageResultExecution timeMemory
759441MetalPower Martian DNA (BOI18_dna)C++14
100 / 100
36 ms4664 KiB
#include <bits/stdc++.h> using namespace std; const int MX = 2e5 + 10; int N, K, R, arr[MX], cnt[MX], req[MX]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> K >> R; for(int i = 0; i < N; i++) cin >> arr[i]; for(int i = 0; i < R; i++){ int B, Q; cin >> B >> Q; req[B] = Q; } int l = 0, r = -1, num = 0; for(int i = 0; i < K; i++){ if(cnt[i] >= req[i]) num++; } int ans = 1e9 + 7; for(; l < N && r < N; l++){ for(; num < K && r < N; ){ ++r; cnt[arr[r]]++; if(cnt[arr[r]] == req[arr[r]]) num++; } if(num == K){ ans = min(ans, r - l + 1); if(cnt[arr[l]] == req[arr[l]]) num--; cnt[arr[l]]--; } } if(ans > N) cout << "impossible" << '\n'; else cout << ans << '\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...