# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
936532 | dshfjka | Martian DNA (BOI18_dna) | C++14 | 46 ms | 7004 KiB |
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 <bits/stdc++.h>
#define LL long long
using namespace std;
int main()
{
LL n,k,r;
scanf("%lld %lld %lld",&n,&k,&r);
LL arr[n+5],brr[n+5];
memset(brr,0,sizeof(brr));
for(LL a=1;a<=n;a++)
{
scanf("%lld",&arr[a]);
}
for(LL a=1;a<=r;a++)
{
LL x,y;
scanf("%lld %lld",&x,&y);
brr[x]=y;
}
LL left=1,right=n;
LL ans=-1;
while(left<=right)
{
LL mid=(left+right)/2;
// printf("mid=%lld\n",mid);
LL all=0;
LL jeje[k+5];
memset(jeje,0,sizeof(jeje));
for(LL a=1;a<=mid;a++)
{
jeje[arr[a]]++;
if(jeje[arr[a]]==brr[arr[a]])all++;
// printf("jeje[%lld]=%lld\n",arr[a],jeje[arr[a]]);
}
if(all==r)
{
ans=mid;
right=mid-1;
continue;
}
bool sudah=0;
for(LL a=mid+1;a<=n;a++)
{
jeje[arr[a-mid]]--;
if(jeje[arr[a-mid]]==brr[arr[a-mid]]-1)all--;
jeje[arr[a]]++;
if(jeje[arr[a]]==brr[arr[a]])all++;
// printf("all = %lld\n",all);
if(all==r)
{
ans=mid;
right=mid-1;
sudah=1;
break;
}
}
if(sudah)continue;
else {
left=mid+1;
}
}
if(ans==-1)printf("impossible\n");
else printf("%lld\n",ans);
}
Compilation message (stderr)
# | 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... |