Submission #458055

# Submission time Handle Problem Language Result Execution time Memory
458055 2021-08-07T23:31:35 Z ZaZo_ Martian DNA (BOI18_dna) C++14
0 / 100
2000 ms 13484 KB
//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]) && mp[arr[l]]<req[arr[l]]))
     {
      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

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 time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 59 ms 2208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2060 ms 13484 KB Time limit exceeded
2 Halted 0 ms 0 KB -