# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1022403 |
2024-07-13T13:06:21 Z |
vjudge1 |
Martian DNA (BOI18_dna) |
C++17 |
|
47 ms |
2900 KB |
#include<iostream>
#include<fstream>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
tuple<int,int,int> mindist(vector<int>&dna,int n,int b,int q,int start,int end)
{
int br=0;
int id1,id2;
int mind=200000;
for(int i=start;i<end;i++)
{
br=0;
if(dna[i]==b)
{
br++;
for(int j=i+1;j<end;j++)
{
if(br==q)
{
id2=j;
break;
}
if(dna[j]==b)
br++;
}
}
mind=min(mind,id2-id1+1);
}
return {mind,id1,id2};
if(br<q) {
if(start-1>=0)
mindist(dna,n,b,q,start-1,end);
if(end+1<n)
mindist(dna,n,b,q,start,end);
}
}
int main()
{
int n,k,r;
cin>>n>>k>>r;
vector<int> dna(n);
vector<int> rep(k);
for(int i=0;i<n;i++)
{cin>>dna[i];
rep[dna[i]]++;}
int mini=200000,maxi=-1;
int b,q;
cin>>b>>q;
if(rep[b]>q)
{
cout<<"impossible"<<endl;
return 0;
}
int br;
tie(br,mini,maxi)=mindist(dna,n,b,q,0,n-1);
for(int i=1;i<r;i++)
{
cin>>b>>q;
if(rep[b]>q)
{
cout<<"impossible"<<endl;
return 0;
}
int tempmin,tempmax;
tie(br,tempmin,tempmax)=mindist(dna,n,b,q,mini,maxi);
mini=tempmin;
maxi=tempmax;
}
cout<<br<<endl;
return 0;
}
Compilation message
dna.cpp: In function 'std::tuple<int, int, int> mindist(std::vector<int>&, int, int, int, int, int)':
dna.cpp:30:26: warning: 'id1' may be used uninitialized in this function [-Wmaybe-uninitialized]
30 | mind=min(mind,id2-id1+1);
| ~~~^~~~
dna.cpp:30:26: warning: 'id2' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
1372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
47 ms |
2900 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |