Submission #643394

#TimeUsernameProblemLanguageResultExecution timeMemory
643394devariaota Martian DNA (BOI18_dna)C++17
68 / 100
2065 ms21132 KiB
#include <bits/stdc++.h> #define ll long long #define fi first #define se second #define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); const ll MOD=1e9+7; using namespace std; ll N,M,K,a[200005]; vector <ll> vec[200005]; vector <pair<ll,ll> > pr[200005]; int main(){ cin>>N>>M>>K; for(int i=1;i<=N;i++){ cin>>a[i]; vec[a[i]].push_back(i); } bool ok=true; for(int i=1;i<=K;i++){ ll x,y; cin>>x>>y; // cout<<vec[x].size()<<' '<<y<<endl; if(vec[x].size()<y){ ok=false; } else{ for(int j=y-1;j<vec[x].size();j++){ pr[i].push_back({vec[x][j-(y-1)],vec[x][j]}); } } } if(!ok){ cout<<"impossible"<<endl; return 0; } ll minn=1e18; for(int i=1;i<=N;i++){ ll maks=0; bool ok=true; for(int j=1;j<=K;j++){ ll l=0; ll r=pr[j].size()-1; ll ans=-1; while(l<=r){ ll m=(l+r)/2; if(pr[j][m].fi>=i){ ans=m; r=m-1; } else{ l=m+1; } } if(ans==-1){ ok=false; break; } maks=max(maks,pr[j][ans].se); } if(ok){ minn=min(minn,maks-i+1); } } cout<<minn<<endl; }

Compilation message (stderr)

dna.cpp: In function 'int main()':
dna.cpp:22:21: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   22 |     if(vec[x].size()<y){
      |        ~~~~~~~~~~~~~^~
dna.cpp:26:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |       for(int j=y-1;j<vec[x].size();j++){
      |                     ~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...