This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<iostream>
#include<fstream>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
int n,r,k;
cin>>n>>k>>r;
vector<int> dna(n);
for(int i=0;i<n;i++) cin>>dna[i];
int mini=200000,maxi=-1;
int br=0;
br=0;
int b,q;
cin>>b>>q;
int id1,id2,id;
while(br<q)
{
vector<int>::iterator it=find(dna.begin(),dna.end(),b);
if(it==dna.end()) break;
id=distance(dna.begin(),it);
if(br==0) id1=id;
dna[id]=-1;
br++;
}
if(br<q)
{
cout<<"impossible"<<endl;
return 0;
}
id2=id;
mini=min(mini,id1);
maxi=max(maxi,id2);
for(int i=1;i<r;i++)
{
cin>>b>>q;
br=0;
id1=mini;
id2=maxi;
while(br<q)
{
vector<int>::iterator it=find(dna.begin()+id1,dna.begin()+id2+1,b);
int j=1;
int count=0;
if(it==dna.begin()+id2+1)
{
while(count==0&&(id1-j>=0||id2+j<n))
{
id1=id1-j;
vector<int>::iterator it1=find(dna.begin()+id1,dna.begin()+id2+1,b);
if(it1==dna.begin()+id2+1)
{
id2+=j;
id1+=j;
vector<int>::iterator it2=find(dna.begin()+id1,dna.begin()+id2+1,b);
if(it2==dna.begin()+id2+1)
{
id2-=j;
j++;
}
else
{
int id=distance(dna.begin(),it2);
dna[id]=-1;
br++;
break;
}
}
else
{
int id=distance(dna.begin(),it1);
dna[id]=-1;
br++;
break;
}
}
}
else
{
int id=distance(dna.begin(),it);
dna[id]=-1;
br++;
continue;
}
}
if(br<q)
{
cout<<"impossible"<<endl;
return 0;
}
mini=min(mini,id1);
maxi=max(maxi,id2);
}
cout<<maxi-mini+1<<endl;
return 0;
}
Compilation message (stderr)
dna.cpp: In function 'int main()':
dna.cpp:19:9: warning: 'id1' may be used uninitialized in this function [-Wmaybe-uninitialized]
19 | int id1,id2,id;
| ^~~
dna.cpp:19:17: warning: 'id' may be used uninitialized in this function [-Wmaybe-uninitialized]
19 | int id1,id2,id;
| ^~
# | 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... |