Submission #420958

# Submission time Handle Problem Language Result Execution time Memory
420958 2021-06-08T15:28:09 Z nicolaalexandra Martian DNA (BOI18_dna) C++14
100 / 100
287 ms 140564 KB
#include <bits/stdc++.h>
#define DIM 200010
#define INF 2000000000
using namespace std;

int aint[DIM*4],v[DIM],f[DIM];
deque <int> d[DIM];
int n,k,r,i,x,y;

void build (int nod, int st, int dr){
    if (st == dr){
        if (f[st])
            aint[nod] = -INF;
        else aint[nod] = INF;

        return;
    }
    int mid = (st+dr)>>1;
    build (nod<<1,st,mid);
    build ((nod<<1)|1,mid+1,dr);

    aint[nod] = min (aint[nod<<1],aint[(nod<<1)|1]);
}

void update (int nod, int st, int dr, int poz, int val){
    if (st == dr){
        aint[nod] = val;
        return;
    }
    int mid = (st+dr)>>1;
    if (poz <= mid)
        update (nod<<1,st,mid,poz,val);
    else update ((nod<<1)|1,mid+1,dr,poz,val);

    aint[nod] = min (aint[nod<<1],aint[(nod<<1)|1]);
}

int main (){

    //ifstream cin ("date.in");
    //ofstream cout ("date.out");

    cin>>n>>k>>r;
    for (i=1;i<=n;i++){
        cin>>v[i];
        v[i]++;
    }

    for (i=1;i<=r;i++){
        cin>>x>>y;
        x++;
        f[x] = y;
    }

    build (1,1,k);

    int sol = INF;
    for (i=1;i<=n;i++){
        d[v[i]].push_back(i);
        if (!f[v[i]])
            continue;

        if (d[v[i]].size() > f[v[i]])
            d[v[i]].pop_front();

        if (d[v[i]].size() == f[v[i]])
            update (1,1,k,v[i],d[v[i]].front());

        sol = min (sol,i - aint[1] + 1);
    }

    if (sol == INF)
        cout<<"impossible";
    else cout<<sol;


    return 0;
}

Compilation message

dna.cpp: In function 'int main()':
dna.cpp:63:28: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   63 |         if (d[v[i]].size() > f[v[i]])
      |             ~~~~~~~~~~~~~~~^~~~~~~~~
dna.cpp:66:28: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   66 |         if (d[v[i]].size() == f[v[i]])
      |             ~~~~~~~~~~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 88 ms 134852 KB Output is correct
2 Correct 93 ms 134980 KB Output is correct
3 Correct 88 ms 134928 KB Output is correct
4 Correct 88 ms 134852 KB Output is correct
5 Correct 95 ms 134932 KB Output is correct
6 Correct 88 ms 134872 KB Output is correct
7 Correct 88 ms 134852 KB Output is correct
8 Correct 94 ms 134852 KB Output is correct
9 Correct 83 ms 134908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 134852 KB Output is correct
2 Correct 89 ms 134904 KB Output is correct
3 Correct 88 ms 134952 KB Output is correct
4 Correct 89 ms 135008 KB Output is correct
5 Correct 87 ms 134900 KB Output is correct
6 Correct 90 ms 134872 KB Output is correct
7 Correct 89 ms 134924 KB Output is correct
8 Correct 88 ms 134888 KB Output is correct
9 Correct 89 ms 134888 KB Output is correct
10 Correct 90 ms 134852 KB Output is correct
11 Correct 87 ms 134888 KB Output is correct
12 Correct 91 ms 134888 KB Output is correct
13 Correct 91 ms 134868 KB Output is correct
14 Correct 87 ms 135000 KB Output is correct
15 Correct 90 ms 134836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 163 ms 136640 KB Output is correct
2 Correct 131 ms 136404 KB Output is correct
3 Correct 141 ms 136208 KB Output is correct
4 Correct 161 ms 136364 KB Output is correct
5 Correct 182 ms 138016 KB Output is correct
6 Correct 134 ms 136892 KB Output is correct
7 Correct 155 ms 137156 KB Output is correct
8 Correct 209 ms 139048 KB Output is correct
9 Correct 146 ms 136656 KB Output is correct
10 Correct 146 ms 136344 KB Output is correct
11 Correct 88 ms 134972 KB Output is correct
12 Correct 91 ms 134980 KB Output is correct
13 Correct 92 ms 135084 KB Output is correct
14 Correct 91 ms 135100 KB Output is correct
15 Correct 89 ms 134996 KB Output is correct
16 Correct 87 ms 134980 KB Output is correct
17 Correct 87 ms 134872 KB Output is correct
18 Correct 96 ms 134852 KB Output is correct
19 Correct 88 ms 134920 KB Output is correct
20 Correct 87 ms 134876 KB Output is correct
21 Correct 87 ms 134940 KB Output is correct
22 Correct 89 ms 134872 KB Output is correct
23 Correct 88 ms 134852 KB Output is correct
24 Correct 91 ms 134944 KB Output is correct
25 Correct 88 ms 134864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 278 ms 138808 KB Output is correct
2 Correct 287 ms 138320 KB Output is correct
3 Correct 205 ms 137772 KB Output is correct
4 Correct 140 ms 136172 KB Output is correct
5 Correct 237 ms 139260 KB Output is correct
6 Correct 281 ms 140564 KB Output is correct
7 Correct 173 ms 136828 KB Output is correct
8 Correct 191 ms 137244 KB Output is correct
9 Correct 143 ms 136572 KB Output is correct
10 Correct 135 ms 136424 KB Output is correct
11 Correct 142 ms 136308 KB Output is correct
12 Correct 140 ms 136588 KB Output is correct
13 Correct 179 ms 138052 KB Output is correct
14 Correct 144 ms 136928 KB Output is correct
15 Correct 174 ms 137028 KB Output is correct
16 Correct 184 ms 139096 KB Output is correct
17 Correct 150 ms 136744 KB Output is correct
18 Correct 144 ms 136348 KB Output is correct
19 Correct 84 ms 134852 KB Output is correct
20 Correct 101 ms 135028 KB Output is correct
21 Correct 91 ms 134992 KB Output is correct
22 Correct 89 ms 135084 KB Output is correct
23 Correct 93 ms 134980 KB Output is correct
24 Correct 88 ms 134932 KB Output is correct
25 Correct 87 ms 134940 KB Output is correct
26 Correct 89 ms 134944 KB Output is correct
27 Correct 89 ms 134852 KB Output is correct
28 Correct 88 ms 134852 KB Output is correct
29 Correct 89 ms 134864 KB Output is correct
30 Correct 100 ms 134896 KB Output is correct
31 Correct 93 ms 134936 KB Output is correct
32 Correct 89 ms 134948 KB Output is correct
33 Correct 87 ms 134888 KB Output is correct