Submission #987619

# Submission time Handle Problem Language Result Execution time Memory
987619 2024-05-23T07:32:40 Z AlphaMale06 Martian DNA (BOI18_dna) C++17
100 / 100
95 ms 24224 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+3;

vector<int> pos[N];
int cnt[N];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k, m;
    cin >> n >> k >> m;
    int a[n];
    for(int i=0; i< n; i++){
        cin >> a[i];
        pos[a[i]].push_back(i);
    }
    int req[k];
    for(int i=0; i < k; i++){
        req[i]=0;
    }
    for(int i=0; i< m; i++){
        int x, y;
        cin >> x >> y;
        req[x]=y;
    }
    multiset<int> st;
    for(int i=0; i< k; i++){
        if(req[i]==cnt[i])st.insert(n+1);
    }
    int ans=n+1;
    for(int i=0; i < n; i++){
        int val = a[i];
        if(cnt[val]<req[val]){
            cnt[val]++;
            if(cnt[val]==req[val])st.insert(pos[val][0]);
        }
        else if(cnt[val]>=req[val] && req[val]!=0){
            st.erase(st.find(pos[val][cnt[val]-req[val]]));
            cnt[val]++;
            st.insert(pos[val][cnt[val]-req[val]]);
        }
        if(st.size()==k)ans=min(ans, i-(*st.begin())+1);
    }
    if(ans==n+1)cout << "impossible\n";
    else cout << ans << '\n';
}

Compilation message

dna.cpp: In function 'int main()':
dna.cpp:46:21: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   46 |         if(st.size()==k)ans=min(ans, i-(*st.begin())+1);
      |            ~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5720 KB Output is correct
2 Correct 2 ms 5724 KB Output is correct
3 Correct 2 ms 5724 KB Output is correct
4 Correct 2 ms 5724 KB Output is correct
5 Correct 2 ms 5724 KB Output is correct
6 Correct 2 ms 5760 KB Output is correct
7 Correct 4 ms 5980 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
9 Correct 2 ms 5724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5724 KB Output is correct
2 Correct 2 ms 5724 KB Output is correct
3 Correct 3 ms 5980 KB Output is correct
4 Correct 3 ms 6028 KB Output is correct
5 Correct 3 ms 5724 KB Output is correct
6 Correct 2 ms 5724 KB Output is correct
7 Correct 2 ms 5724 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
9 Correct 2 ms 5724 KB Output is correct
10 Correct 2 ms 5724 KB Output is correct
11 Correct 3 ms 5724 KB Output is correct
12 Correct 2 ms 5720 KB Output is correct
13 Correct 2 ms 5724 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 2 ms 5724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 8284 KB Output is correct
2 Correct 17 ms 8468 KB Output is correct
3 Correct 18 ms 8024 KB Output is correct
4 Correct 17 ms 8240 KB Output is correct
5 Correct 35 ms 14336 KB Output is correct
6 Correct 11 ms 8024 KB Output is correct
7 Correct 13 ms 8028 KB Output is correct
8 Correct 66 ms 24224 KB Output is correct
9 Correct 20 ms 9052 KB Output is correct
10 Correct 24 ms 8028 KB Output is correct
11 Correct 2 ms 5724 KB Output is correct
12 Correct 2 ms 5724 KB Output is correct
13 Correct 3 ms 5980 KB Output is correct
14 Correct 3 ms 5980 KB Output is correct
15 Correct 3 ms 5724 KB Output is correct
16 Correct 2 ms 5724 KB Output is correct
17 Correct 2 ms 5724 KB Output is correct
18 Correct 2 ms 5720 KB Output is correct
19 Correct 2 ms 5724 KB Output is correct
20 Correct 2 ms 5724 KB Output is correct
21 Correct 2 ms 5724 KB Output is correct
22 Correct 2 ms 5528 KB Output is correct
23 Correct 2 ms 5724 KB Output is correct
24 Correct 2 ms 5724 KB Output is correct
25 Correct 2 ms 5724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 14932 KB Output is correct
2 Correct 59 ms 13140 KB Output is correct
3 Correct 49 ms 12948 KB Output is correct
4 Correct 19 ms 8032 KB Output is correct
5 Correct 52 ms 13104 KB Output is correct
6 Correct 95 ms 23520 KB Output is correct
7 Correct 50 ms 9040 KB Output is correct
8 Correct 72 ms 10116 KB Output is correct
9 Correct 15 ms 8280 KB Output is correct
10 Correct 17 ms 8216 KB Output is correct
11 Correct 20 ms 7896 KB Output is correct
12 Correct 17 ms 8252 KB Output is correct
13 Correct 36 ms 14212 KB Output is correct
14 Correct 11 ms 8028 KB Output is correct
15 Correct 14 ms 8028 KB Output is correct
16 Correct 66 ms 24148 KB Output is correct
17 Correct 20 ms 9044 KB Output is correct
18 Correct 19 ms 8280 KB Output is correct
19 Correct 2 ms 5724 KB Output is correct
20 Correct 2 ms 5724 KB Output is correct
21 Correct 3 ms 5980 KB Output is correct
22 Correct 3 ms 5980 KB Output is correct
23 Correct 2 ms 5720 KB Output is correct
24 Correct 3 ms 5720 KB Output is correct
25 Correct 2 ms 5724 KB Output is correct
26 Correct 2 ms 5724 KB Output is correct
27 Correct 3 ms 5724 KB Output is correct
28 Correct 2 ms 5724 KB Output is correct
29 Correct 2 ms 5724 KB Output is correct
30 Correct 2 ms 5760 KB Output is correct
31 Correct 2 ms 5724 KB Output is correct
32 Correct 2 ms 5724 KB Output is correct
33 Correct 2 ms 5724 KB Output is correct