Submission #458056

#TimeUsernameProblemLanguageResultExecution timeMemory
458056ZaZo_ Martian DNA (BOI18_dna)C++14
0 / 100
2087 ms11752 KiB
//Sorry but iam targeting IOI :)) //NEVER LOSE HOPE #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #include <bits/stdc++.h> #define endl "\n" #define ceil(a,b) (a+(b-1))/b #define all(v) v.begin(),v.end() #define int long long int #define Hidden ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); using namespace std; const int N=3e4+10,mod = 1e9+7; int32_t main(){ int n,k,rr; cin>>n>>k>>rr; int arr[n]; map<int,int>mp,req,dif; set<int>st; for(int i = 0 ; i < n ; i ++) { cin>>arr[i]; mp[arr[i]]++; } int flg=0; for(int i = 0 ; i < rr ; i ++) { int x,y; cin>>x>>y; if(mp[x]<y) flg=1; req[x]=y; } if(flg||mp.size()<k) { cout<<"impossible"; return 0; } int l=0,r=n-1; while(r>l) { if((req.count(arr[r]) && mp[arr[r]]-1 < req[arr[r]]) || mp.size()-(mp[arr[r]]-1==0)<k) break; else { mp[arr[r]]--; if(mp[arr[r]]==0) mp.erase(arr[r]); r--; } } int ans=r-l+1; while(r<n) { l++; mp[arr[l-1]]--; if((req.count(arr[l-1]) && mp[arr[l-1]]<req[arr[l-1]])) { while(r<n) { r++; mp[arr[r]]++; if(arr[r]==arr[l-1]) break; } } if(mp[arr[l-1]]==0) mp.erase(arr[l-1]); if(mp.size()<k) { while(r<n) { r++; mp[arr[r]]++; if(mp.size()==k) break; } } int cnt=0; auto it=req.begin(); for(;it!=req.end();it++) { if(it->second <= mp[it->first]) cnt++; } if(mp.size()>=k && cnt==req.size()) ans=min(ans,r-l+1); } cout<<ans<<endl; }

Compilation message (stderr)

dna.cpp: In function 'int32_t main()':
dna.cpp:32:20: warning: comparison of integer expressions of different signedness: 'std::map<long long int, long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   32 |   if(flg||mp.size()<k)
      |           ~~~~~~~~~^~
dna.cpp:40:88: warning: comparison of integer expressions of different signedness: 'std::map<long long int, long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   40 |     if((req.count(arr[r]) && mp[arr[r]]-1 < req[arr[r]]) || mp.size()-(mp[arr[r]]-1==0)<k) break;
      |                                                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
dna.cpp:63:18: warning: comparison of integer expressions of different signedness: 'std::map<long long int, long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   63 |      if(mp.size()<k)
      |         ~~~~~~~~~^~
dna.cpp:69:22: warning: comparison of integer expressions of different signedness: 'std::map<long long int, long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   69 |          if(mp.size()==k) break;
      |             ~~~~~~~~~^~~
dna.cpp:79:18: warning: comparison of integer expressions of different signedness: 'std::map<long long int, long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   79 |      if(mp.size()>=k && cnt==req.size())
      |         ~~~~~~~~~^~~
dna.cpp:79:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::map<long long int, long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |      if(mp.size()>=k && cnt==req.size())
      |                         ~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...