Submission #862878

#TimeUsernameProblemLanguageResultExecution timeMemory
862878iskhakkutbilim Martian DNA (BOI18_dna)C++17
100 / 100
28 ms5844 KiB
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define all(a) a.begin(), a.end() const int N = 2e5; int n, k, q; vector<int> a; vector<pair<int, int> > query; int nuk[N+10], need[N + 10]; main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k >> q; a.resize(n); for(int i = 0;i < n; i++){ cin >> a[i]; nuk[a[i]]++; } for(int i = 0;i < q; i++){ int c, cnt; cin >> c >> cnt; query.push_back({c, cnt}); need[c] = cnt; } for(auto [c, cnt] : query){ if(nuk[c] < cnt){ cout << "impossible"; return 0; } } for(int i = 0;i < n; i++) nuk[a[i]] = 0; int ans = n, ok = 0; for(int l = 0, r = 0; l < n; l++){ while(r < n && ok < q){ nuk[a[r]]++; if(nuk[a[r]] == need[a[r]]){ ok++; } r++; } if(ok > q) assert(false); if(ok == q){ ans = min(ans, r - l); } if(nuk[a[l]] == need[a[l]]){ ok--; } nuk[a[l]]--; } cout << ans; return 0; }

Compilation message (stderr)

dna.cpp:16:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   16 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...