#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
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;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
856 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1093 ms |
1588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2051 ms |
2644 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |