Submission #557408

# Submission time Handle Problem Language Result Execution time Memory
557408 2022-05-05T09:42:38 Z hibiki Martian DNA (BOI18_dna) C++11
100 / 100
125 ms 19608 KB
#include<bits/stdc++.h>
using namespace std;

#define PB push_back
#define F first
#define S second

int n,k,r;
int arr[200200],req[200200],idx[200200];
vector<int> ty[200200];
set<int> s;

int main()
{
    memset(idx,-1,sizeof(idx));
    scanf("%d %d %d",&n,&k,&r);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
        ty[arr[i]].PB(i);
    }
    for(int i=0;i<r;i++)
    {
        int a;
        scanf("%d",&a);
        scanf("%d",&req[a]);
    }
    int ans=1e9;
    for(int i=0;i<n;i++)
    {
        if(req[arr[i]]==0)continue;

        int prev=idx[arr[i]];
        int nw=idx[arr[i]]+1;
        int prev_req=max(-1,prev-req[arr[i]]+1);
        int nw_req=max(-1,nw-req[arr[i]]+1);

        if(prev_req==-1)
            s.erase(prev_req);
        else
            s.erase(ty[arr[i]][prev_req]);
        if(nw_req==-1)
            s.insert(nw_req);
        else
            s.insert(ty[arr[i]][nw_req]);
        if(s.size() == r && *s.begin() != -1 )
            ans=min(ans,i - *s.begin() + 1 );

        idx[arr[i]]++;
    }
    if(ans==1e9)
        printf("impossible\n");
    else
        printf("%d\n",ans);
    return 0;
}

Compilation message

dna.cpp: In function 'int main()':
dna.cpp:46:21: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   46 |         if(s.size() == r && *s.begin() != -1 )
      |            ~~~~~~~~~^~~~
dna.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     scanf("%d %d %d",&n,&k,&r);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
dna.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         scanf("%d",&arr[i]);
      |         ~~~~~^~~~~~~~~~~~~~
dna.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         scanf("%d",&a);
      |         ~~~~~^~~~~~~~~
dna.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         scanf("%d",&req[a]);
      |         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5716 KB Output is correct
2 Correct 3 ms 5716 KB Output is correct
3 Correct 4 ms 5716 KB Output is correct
4 Correct 3 ms 5796 KB Output is correct
5 Correct 3 ms 5716 KB Output is correct
6 Correct 3 ms 5792 KB Output is correct
7 Correct 3 ms 5796 KB Output is correct
8 Correct 4 ms 5796 KB Output is correct
9 Correct 3 ms 5716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5736 KB Output is correct
2 Correct 4 ms 5804 KB Output is correct
3 Correct 3 ms 5844 KB Output is correct
4 Correct 4 ms 5972 KB Output is correct
5 Correct 6 ms 5872 KB Output is correct
6 Correct 4 ms 5808 KB Output is correct
7 Correct 3 ms 5792 KB Output is correct
8 Correct 3 ms 5716 KB Output is correct
9 Correct 3 ms 5788 KB Output is correct
10 Correct 4 ms 5716 KB Output is correct
11 Correct 3 ms 5796 KB Output is correct
12 Correct 3 ms 5716 KB Output is correct
13 Correct 4 ms 5716 KB Output is correct
14 Correct 3 ms 5716 KB Output is correct
15 Correct 4 ms 5716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 8384 KB Output is correct
2 Correct 27 ms 8012 KB Output is correct
3 Correct 45 ms 7960 KB Output is correct
4 Correct 29 ms 8204 KB Output is correct
5 Correct 39 ms 10292 KB Output is correct
6 Correct 26 ms 7996 KB Output is correct
7 Correct 21 ms 8036 KB Output is correct
8 Correct 51 ms 14048 KB Output is correct
9 Correct 29 ms 8856 KB Output is correct
10 Correct 31 ms 8084 KB Output is correct
11 Correct 4 ms 5844 KB Output is correct
12 Correct 4 ms 5844 KB Output is correct
13 Correct 4 ms 5844 KB Output is correct
14 Correct 4 ms 5972 KB Output is correct
15 Correct 4 ms 5812 KB Output is correct
16 Correct 4 ms 5844 KB Output is correct
17 Correct 4 ms 5716 KB Output is correct
18 Correct 4 ms 5768 KB Output is correct
19 Correct 3 ms 5716 KB Output is correct
20 Correct 3 ms 5716 KB Output is correct
21 Correct 3 ms 5796 KB Output is correct
22 Correct 3 ms 5800 KB Output is correct
23 Correct 3 ms 5792 KB Output is correct
24 Correct 3 ms 5796 KB Output is correct
25 Correct 3 ms 5796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 124 ms 14784 KB Output is correct
2 Correct 95 ms 13180 KB Output is correct
3 Correct 57 ms 11096 KB Output is correct
4 Correct 26 ms 7928 KB Output is correct
5 Correct 68 ms 12192 KB Output is correct
6 Correct 125 ms 19608 KB Output is correct
7 Correct 89 ms 9196 KB Output is correct
8 Correct 97 ms 10040 KB Output is correct
9 Correct 33 ms 8328 KB Output is correct
10 Correct 27 ms 8012 KB Output is correct
11 Correct 31 ms 7872 KB Output is correct
12 Correct 30 ms 8224 KB Output is correct
13 Correct 37 ms 10392 KB Output is correct
14 Correct 28 ms 8012 KB Output is correct
15 Correct 20 ms 8104 KB Output is correct
16 Correct 52 ms 14124 KB Output is correct
17 Correct 28 ms 8908 KB Output is correct
18 Correct 35 ms 8116 KB Output is correct
19 Correct 4 ms 5844 KB Output is correct
20 Correct 4 ms 5844 KB Output is correct
21 Correct 6 ms 5936 KB Output is correct
22 Correct 11 ms 5940 KB Output is correct
23 Correct 4 ms 5844 KB Output is correct
24 Correct 4 ms 5844 KB Output is correct
25 Correct 4 ms 5844 KB Output is correct
26 Correct 4 ms 5792 KB Output is correct
27 Correct 3 ms 5716 KB Output is correct
28 Correct 3 ms 5716 KB Output is correct
29 Correct 3 ms 5716 KB Output is correct
30 Correct 3 ms 5716 KB Output is correct
31 Correct 4 ms 5792 KB Output is correct
32 Correct 3 ms 5716 KB Output is correct
33 Correct 3 ms 5716 KB Output is correct