Submission #330266

#TimeUsernameProblemLanguageResultExecution timeMemory
330266nandonathaniel Martian DNA (BOI18_dna)C++14
100 / 100
134 ms12672 KiB
#include<bits/stdc++.h> using namespace std; int mini[200005],byk[200005]; int s[200005]; int main(){ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); int n,k,r,x,y; cin >> n >> k >> r; for(int i=0;i<n;i++)cin >> s[i]; for(int i=1;i<=r;i++){ cin >> x >> y; mini[x]=y; } set<int> valid; for(int i=0;i<k;i++){ if(mini[i]==0)valid.insert(i); } int ans=n+1,awal=0,akhir=0; byk[s[0]]++; if(byk[s[0]]==mini[s[0]])valid.insert(s[0]); while(awal<=akhir && akhir<n){ bool stat=(valid.size()==k); if(!stat){ if(akhir<n-1){ akhir++; byk[s[akhir]]++; if(byk[s[akhir]]==mini[s[akhir]])valid.insert(s[akhir]); } else break; } else{ ans=min(ans,akhir-awal+1); byk[s[awal]]--; if(byk[s[awal]]==mini[s[awal]]-1)valid.erase(s[awal]); awal++; } } if(ans==n+1)cout << "impossible\n"; else cout << ans << '\n'; return 0; }

Compilation message (stderr)

dna.cpp: In function 'int main()':
dna.cpp:24:29: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   24 |      bool stat=(valid.size()==k);
      |                 ~~~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...