Submission #934941

# Submission time Handle Problem Language Result Execution time Memory
934941 2024-02-28T08:13:05 Z ttamx Martian DNA (BOI18_dna) C++17
100 / 100
23 ms 3932 KB
#include<bits/stdc++.h>

using namespace std;

const int N=2e5+5;

int n,k,r;
int a[N],mn[N],cnt[N];

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n >> k >> r;
    for(int i=1;i<=n;i++)cin >> a[i];
    for(int i=0;i<r;i++){
        int x,y;
        cin >> x >> y;
        mn[x]=y;
    }
    int p=1;
    for(int i=0;i<k;i++)while(cnt[i]<mn[i]&&p<=n)cnt[a[p++]]++;
    for(int i=0;i<k;i++)if(cnt[i]<mn[i])cout << "impossible\n",exit(0);
    int ans=p-1;
    for(int i=1;i<n;i++){
        cnt[a[i]]--;
        while(cnt[a[i]]<mn[a[i]]&&p<=n)cnt[a[p++]]++;
        if(cnt[a[i]]<mn[a[i]])break;
        ans=min(ans,p-i-1);
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2456 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2516 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2396 KB Output is correct
2 Correct 9 ms 2396 KB Output is correct
3 Correct 10 ms 2524 KB Output is correct
4 Correct 9 ms 2396 KB Output is correct
5 Correct 12 ms 2908 KB Output is correct
6 Correct 8 ms 2396 KB Output is correct
7 Correct 9 ms 3164 KB Output is correct
8 Correct 14 ms 3904 KB Output is correct
9 Correct 12 ms 3524 KB Output is correct
10 Correct 9 ms 2908 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2648 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2512 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 2808 KB Output is correct
2 Correct 18 ms 2652 KB Output is correct
3 Correct 15 ms 2652 KB Output is correct
4 Correct 9 ms 2516 KB Output is correct
5 Correct 21 ms 2648 KB Output is correct
6 Correct 23 ms 2644 KB Output is correct
7 Correct 11 ms 2648 KB Output is correct
8 Correct 18 ms 2648 KB Output is correct
9 Correct 8 ms 2644 KB Output is correct
10 Correct 9 ms 2396 KB Output is correct
11 Correct 9 ms 2520 KB Output is correct
12 Correct 9 ms 2396 KB Output is correct
13 Correct 12 ms 2652 KB Output is correct
14 Correct 8 ms 2396 KB Output is correct
15 Correct 9 ms 3112 KB Output is correct
16 Correct 14 ms 3932 KB Output is correct
17 Correct 11 ms 3420 KB Output is correct
18 Correct 9 ms 2908 KB Output is correct
19 Correct 1 ms 2516 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 0 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 0 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 0 ms 2512 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct