Submission #370111

# Submission time Handle Problem Language Result Execution time Memory
370111 2021-02-23T09:56:15 Z gratus907 Martian DNA (BOI18_dna) C++17
100 / 100
131 ms 6764 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) ((x).begin()),((x).end())
#define int ll
using pii = pair<int, int>;
#define INF 0x7f7f7f7f7f7f7f7f
const bool debug = false;

int n, k, r;
vector <int> dna;
int req[202020];
int occ[202020];
int need;
int ans = INF;
int32_t main()
{
    cin >> n >> k >> r;
    dna.resize(n);
    for (int i = 0; i<n; i++)
    {
        cin >> dna[i];
        occ[dna[i]]++;
    }
    for (int i = 0; i<r; i++)
    {
        int a, b; cin >> a >> b;
        req[a] = b;
        need++;
    }
    int j = 0;
    for (int i = 0; i<n; i++)
    {
        while(need && j < n)
        {
            req[dna[j]]--;
            if (req[dna[j]]==0)
                need--;
            j++;
        }
        if (!need) ans = min(ans, j-i);
        if (!req[dna[i]])
            need++;
        req[dna[i]]++;
    }
    if (ans > n)
        cout << "impossible\n";
    else cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 2284 KB Output is correct
2 Correct 37 ms 2432 KB Output is correct
3 Correct 36 ms 2284 KB Output is correct
4 Correct 35 ms 2284 KB Output is correct
5 Correct 61 ms 4332 KB Output is correct
6 Correct 34 ms 2304 KB Output is correct
7 Correct 41 ms 2560 KB Output is correct
8 Correct 88 ms 6252 KB Output is correct
9 Correct 54 ms 2924 KB Output is correct
10 Correct 34 ms 2412 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 4972 KB Output is correct
2 Correct 87 ms 4460 KB Output is correct
3 Correct 74 ms 4332 KB Output is correct
4 Correct 36 ms 2540 KB Output is correct
5 Correct 131 ms 5612 KB Output is correct
6 Correct 118 ms 6764 KB Output is correct
7 Correct 66 ms 3052 KB Output is correct
8 Correct 65 ms 3436 KB Output is correct
9 Correct 34 ms 2304 KB Output is correct
10 Correct 36 ms 2284 KB Output is correct
11 Correct 40 ms 2284 KB Output is correct
12 Correct 36 ms 2284 KB Output is correct
13 Correct 65 ms 4332 KB Output is correct
14 Correct 35 ms 2412 KB Output is correct
15 Correct 40 ms 2540 KB Output is correct
16 Correct 74 ms 6252 KB Output is correct
17 Correct 53 ms 3052 KB Output is correct
18 Correct 38 ms 2284 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 2 ms 492 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct