Submission #940487

#TimeUsernameProblemLanguageResultExecution timeMemory
940487irmuun Martian DNA (BOI18_dna)C++17
0 / 100
2079 ms30384 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define ff first #define ss second #define all(s) s.begin(),s.end() #define rall(s) s.rbegin(),s.rend() int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n,k,r; cin>>n>>k>>r; int a[n]; set<int>st[k]; for(int i=0;i<k;i++){ st[i].insert(n); } for(int i=0;i<n;i++){ cin>>a[i]; st[a[i]].insert(i); } vector<bool>need(k,0); int b[r],q[r]; bool ok=true; int R=0; for(int i=0;i<r;i++){ cin>>b[i]>>q[i]; need[b[i]]=true; if((int)st[b[i]].size()-1<q[i]){ cout<<"impossible"; return 0; } q[i]--; R=max(R,*st[b[i]].begin()); while(q[i]--){ st[b[i]].erase(st[b[i]].begin()); R=max(R,*st[b[i]].begin()); } } int ans=n; for(int i=0;i<n;i++){ if(R<n) ans=min(ans,R-i+1); if(need[a[i]]==true){ st[a[i]].erase(st[a[i]].begin()); if(!st[a[i]].empty()){ R=max(R,*st[a[i]].begin()); } } } cout<<ans; }

Compilation message (stderr)

dna.cpp: In function 'int main()':
dna.cpp:27:10: warning: unused variable 'ok' [-Wunused-variable]
   27 |     bool ok=true;
      |          ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...