Submission #529173

# Submission time Handle Problem Language Result Execution time Memory
529173 2022-02-22T10:52:45 Z ToroTN Martian DNA (BOI18_dna) C++14
100 / 100
63 ms 4568 KB
#include<bits/stdc++.h>
using namespace std;
int n,m,t,want[200005],num1,num2,a[200005],st,md,ed,hsh[200005],cnt,type,kanttee;
int main()
{
    scanf("%d%d%d",&n,&m,&t);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        a[i]+=1;
    }
    for(int i=1;i<=t;i++)
    {
        scanf("%d%d",&num1,&num2);
        want[num1+1]=max(want[num1+1],num2);
    }
    st=1;
    ed=n;
    while(ed>=st)
    {
        type=-1;
        md=(st+ed)/2;
        //printf("%d %d %d\n",st,md,ed);
        kanttee=m-t;
        memset(hsh,0,sizeof hsh);
        for(int i=1;i<=md;i++)
        {
            ++hsh[a[i]];
            if(hsh[a[i]]==want[a[i]])
            {
                ++kanttee;
            }
        }
        //printf("1 %d\n",kanttee);
        if(kanttee==m)
        {
            type=0;
        }
        for(int i=2;i<=n-md+1;i++)
        {
            --hsh[a[i-1]];
            if(hsh[a[i-1]]==want[a[i-1]]-1)
            {
                --kanttee;
            }
            ++hsh[a[i+md-1]];
            if(hsh[a[i+md-1]]==want[a[i+md-1]])
            {
                ++kanttee;
            }
            //printf("%d %d\n",i,kanttee);
            if(kanttee==m)
            {
                type=0;
            }
        }
        if(type==0)
        {
            ed=md-1;
        }else
        {
            st=md+1;
        }
    }
    if(st==n+1)
    {
        printf("impossible\n");
    }else
    {
        printf("%d\n",st);
    }
}

Compilation message

dna.cpp: In function 'int main()':
dna.cpp:6:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 |     scanf("%d%d%d",&n,&m,&t);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
dna.cpp:9:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |         scanf("%d",&a[i]);
      |         ~~~~~^~~~~~~~~~~~
dna.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         scanf("%d%d",&num1,&num2);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1100 KB Output is correct
2 Correct 1 ms 1068 KB Output is correct
3 Correct 1 ms 1056 KB Output is correct
4 Correct 1 ms 1060 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 2 ms 972 KB Output is correct
8 Correct 2 ms 992 KB Output is correct
9 Correct 1 ms 1088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1100 KB Output is correct
2 Correct 1 ms 1100 KB Output is correct
3 Correct 2 ms 1080 KB Output is correct
4 Correct 2 ms 1080 KB Output is correct
5 Correct 2 ms 1100 KB Output is correct
6 Correct 1 ms 1076 KB Output is correct
7 Correct 2 ms 1064 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 1060 KB Output is correct
10 Correct 1 ms 972 KB Output is correct
11 Correct 1 ms 1064 KB Output is correct
12 Correct 1 ms 1072 KB Output is correct
13 Correct 1 ms 972 KB Output is correct
14 Correct 1 ms 1064 KB Output is correct
15 Correct 1 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 2212 KB Output is correct
2 Correct 29 ms 2252 KB Output is correct
3 Correct 33 ms 2276 KB Output is correct
4 Correct 31 ms 2212 KB Output is correct
5 Correct 36 ms 3032 KB Output is correct
6 Correct 29 ms 2316 KB Output is correct
7 Correct 23 ms 2316 KB Output is correct
8 Correct 46 ms 3148 KB Output is correct
9 Correct 35 ms 2820 KB Output is correct
10 Correct 30 ms 2252 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
12 Correct 2 ms 1056 KB Output is correct
13 Correct 2 ms 1088 KB Output is correct
14 Correct 2 ms 1100 KB Output is correct
15 Correct 2 ms 1060 KB Output is correct
16 Correct 2 ms 1064 KB Output is correct
17 Correct 1 ms 1060 KB Output is correct
18 Correct 1 ms 972 KB Output is correct
19 Correct 1 ms 1064 KB Output is correct
20 Correct 1 ms 1064 KB Output is correct
21 Correct 1 ms 1064 KB Output is correct
22 Correct 1 ms 1068 KB Output is correct
23 Correct 1 ms 1064 KB Output is correct
24 Correct 1 ms 972 KB Output is correct
25 Correct 1 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 3872 KB Output is correct
2 Correct 48 ms 3604 KB Output is correct
3 Correct 57 ms 3308 KB Output is correct
4 Correct 32 ms 2184 KB Output is correct
5 Correct 57 ms 4372 KB Output is correct
6 Correct 63 ms 4568 KB Output is correct
7 Correct 32 ms 2892 KB Output is correct
8 Correct 45 ms 2992 KB Output is correct
9 Correct 29 ms 2252 KB Output is correct
10 Correct 31 ms 2232 KB Output is correct
11 Correct 33 ms 2248 KB Output is correct
12 Correct 31 ms 2196 KB Output is correct
13 Correct 36 ms 2980 KB Output is correct
14 Correct 28 ms 2160 KB Output is correct
15 Correct 24 ms 2380 KB Output is correct
16 Correct 42 ms 3116 KB Output is correct
17 Correct 35 ms 2796 KB Output is correct
18 Correct 30 ms 2220 KB Output is correct
19 Correct 2 ms 1100 KB Output is correct
20 Correct 1 ms 1100 KB Output is correct
21 Correct 1 ms 1100 KB Output is correct
22 Correct 2 ms 1092 KB Output is correct
23 Correct 2 ms 1100 KB Output is correct
24 Correct 2 ms 1100 KB Output is correct
25 Correct 1 ms 972 KB Output is correct
26 Correct 1 ms 976 KB Output is correct
27 Correct 1 ms 976 KB Output is correct
28 Correct 1 ms 976 KB Output is correct
29 Correct 1 ms 972 KB Output is correct
30 Correct 1 ms 1068 KB Output is correct
31 Correct 1 ms 976 KB Output is correct
32 Correct 1 ms 1064 KB Output is correct
33 Correct 1 ms 1060 KB Output is correct