Submission #1022163

# Submission time Handle Problem Language Result Execution time Memory
1022163 2024-07-13T10:40:31 Z vjudge1 Martian DNA (BOI18_dna) C++17
100 / 100
154 ms 17236 KB
#include <iostream>
//#include <bits/stdc++.h>
#include <iomanip>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
typedef vector<ll> vi;
typedef vector<bool> vb;
const ll mm = 1000000007;
const int maxn = 2e5 + 1;



int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    ll n, k, r; cin >> n >> k >> r;
    vi a(n), kb(n);
    map<ll, ll> g;
    vb b(r);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < r; i++) {
        ll x, y; cin >> x >> y;
        g[x] = y;
    }

    ll rez = n+1, brojdobrih=0;
    ll st = 0,end=0;

    ll p = a[end];
    kb[p]++;
    if (kb[p] == g[p]) {
        brojdobrih++;
    }
    

    while (st<n) {
        /*
        cout << "STANJE" << endl;
        cout << "st i end:" << st << " i " << end << endl;
        cout << "brojdobrih: " << brojdobrih << endl;
        for (auto x : kb) cout << x << " ";
        cout << endl << endl;*/

        if (brojdobrih < r) {
            if (end == n - 1) { //
                st = n;
            }
            else {
                end++;
                ll p = a[end];
                kb[p]++;
                if (kb[p] == g[p]) {
                    brojdobrih++;
                }
            }

        }
        else {
            //cout << "jupi!" << endl;
            rez = min(rez, end - st + 1);

            ll p = a[st];
            kb[p]--;
            if (g[p] == 0) {
                //:)
            }
            else if(kb[p]<g[p]){
                brojdobrih--;
            }
            st++;

        }
    


    }

    if (rez == n + 1) cout << "impossible" << endl;
    else cout << rez << endl;


    return 0;

}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 3932 KB Output is correct
2 Correct 11 ms 3932 KB Output is correct
3 Correct 13 ms 4036 KB Output is correct
4 Correct 15 ms 3932 KB Output is correct
5 Correct 70 ms 9552 KB Output is correct
6 Correct 12 ms 3928 KB Output is correct
7 Correct 15 ms 3932 KB Output is correct
8 Correct 109 ms 17236 KB Output is correct
9 Correct 42 ms 4952 KB Output is correct
10 Correct 15 ms 3932 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 98 ms 10328 KB Output is correct
2 Correct 87 ms 8796 KB Output is correct
3 Correct 70 ms 8528 KB Output is correct
4 Correct 10 ms 3928 KB Output is correct
5 Correct 86 ms 11980 KB Output is correct
6 Correct 154 ms 16724 KB Output is correct
7 Correct 33 ms 4952 KB Output is correct
8 Correct 59 ms 5888 KB Output is correct
9 Correct 10 ms 3932 KB Output is correct
10 Correct 13 ms 3840 KB Output is correct
11 Correct 13 ms 4032 KB Output is correct
12 Correct 11 ms 4012 KB Output is correct
13 Correct 76 ms 9556 KB Output is correct
14 Correct 12 ms 3928 KB Output is correct
15 Correct 15 ms 3928 KB Output is correct
16 Correct 103 ms 17188 KB Output is correct
17 Correct 46 ms 5456 KB Output is correct
18 Correct 17 ms 3928 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct