This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//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];
}
int flg=0;
for(int i = 0 ; i < rr ; i ++)
{
int x,y;
cin>>x>>y;
req[x]=y;
}
int l=0,r=0,ans=INT_MAX,cnt=0;
while(l<=r)
{
while(r<n && cnt<req.size())
{
mp[arr[r]]++;
if(req.count(arr[r]) && mp[arr[r]]==req[arr[r]]) cnt++;
r++;
}
if(cnt==req.size()) ans=min(ans,r-l);
mp[arr[l]]--;
if(req.count(arr[l])&&req[arr[l]]>mp[arr[l]]) cnt--;
l++;
}
if(ans==INT_MAX)
{
cout<<"impossible"<<endl;
return 0;
}
cout<<ans<<endl;
}
Compilation message (stderr)
dna.cpp: In function 'int32_t main()':
dna.cpp:33:21: 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]
33 | while(r<n && cnt<req.size())
| ~~~^~~~~~~~~~~
dna.cpp:39:11: 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]
39 | if(cnt==req.size()) ans=min(ans,r-l);
| ~~~^~~~~~~~~~~~
dna.cpp:23:7: warning: unused variable 'flg' [-Wunused-variable]
23 | int flg=0;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |