Submission #557408

#TimeUsernameProblemLanguageResultExecution timeMemory
557408hibiki Martian DNA (BOI18_dna)C++11
100 / 100
125 ms19608 KiB
#include<bits/stdc++.h> using namespace std; #define PB push_back #define F first #define S second int n,k,r; int arr[200200],req[200200],idx[200200]; vector<int> ty[200200]; set<int> s; int main() { memset(idx,-1,sizeof(idx)); scanf("%d %d %d",&n,&k,&r); for(int i=0;i<n;i++) { scanf("%d",&arr[i]); ty[arr[i]].PB(i); } for(int i=0;i<r;i++) { int a; scanf("%d",&a); scanf("%d",&req[a]); } int ans=1e9; for(int i=0;i<n;i++) { if(req[arr[i]]==0)continue; int prev=idx[arr[i]]; int nw=idx[arr[i]]+1; int prev_req=max(-1,prev-req[arr[i]]+1); int nw_req=max(-1,nw-req[arr[i]]+1); if(prev_req==-1) s.erase(prev_req); else s.erase(ty[arr[i]][prev_req]); if(nw_req==-1) s.insert(nw_req); else s.insert(ty[arr[i]][nw_req]); if(s.size() == r && *s.begin() != -1 ) ans=min(ans,i - *s.begin() + 1 ); idx[arr[i]]++; } if(ans==1e9) printf("impossible\n"); else printf("%d\n",ans); return 0; }

Compilation message (stderr)

dna.cpp: In function 'int main()':
dna.cpp:46:21: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   46 |         if(s.size() == r && *s.begin() != -1 )
      |            ~~~~~~~~~^~~~
dna.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     scanf("%d %d %d",&n,&k,&r);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
dna.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         scanf("%d",&arr[i]);
      |         ~~~~~^~~~~~~~~~~~~~
dna.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         scanf("%d",&a);
      |         ~~~~~^~~~~~~~~
dna.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         scanf("%d",&req[a]);
      |         ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...