답안 #458056

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
458056 2021-08-07T23:38:09 Z ZaZo_ Martian DNA (BOI18_dna) C++14
0 / 100
2000 ms 11752 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-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

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())
      |                         ~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 204 KB Output is correct
3 Incorrect 3 ms 488 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 1824 KB Output is correct
2 Correct 44 ms 2216 KB Output is correct
3 Correct 84 ms 2264 KB Output is correct
4 Correct 68 ms 2216 KB Output is correct
5 Incorrect 387 ms 8072 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2087 ms 11752 KB Time limit exceeded
2 Halted 0 ms 0 KB -