Submission #541277

# Submission time Handle Problem Language Result Execution time Memory
541277 2022-03-22T21:40:02 Z Lobo Martian DNA (BOI18_dna) C++17
100 / 100
35 ms 6860 KB
#include<bits/stdc++.h>
using namespace std;

const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()

const int maxn = 2e5+10;

int n,k,R,s[maxn], mn[maxn], qtd[maxn];

void solve() {
    cin >> n >> k >> R;
    for(int i = 1; i <= n; i++) {
        cin >> s[i];
    }
    int q = R;
    for(int i = 1; i <= R; i++) {
        int id;
        cin >> id;
        cin >> mn[id];
    }

    int ans = inf;
    int r = 0;
    for(int i = 1; i <= n; i++) {
        while(r != n && q != 0) {
            //aumenta r
            r++;
            qtd[s[r]]++;
            if(qtd[s[r]] == mn[s[r]]) {
                q--;
            }
        }

        if(q == 0) ans = min(ans, r-i+1);

        //tira i
        qtd[s[i]]--;
        if(qtd[s[i]] == mn[s[i]]-1) {
            q++;
        }
    }

    if(ans == inf) cout << "impossible" << endl;
    else cout << ans << endl;


}

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(0);

    // freopen("in.in", "r", stdin);
    // freopen("out.out", "w", stdout);

    int tt = 1;
    // cin >> tt;
    while(tt--) solve();

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 388 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 1876 KB Output is correct
2 Correct 12 ms 2260 KB Output is correct
3 Correct 12 ms 2260 KB Output is correct
4 Correct 12 ms 2312 KB Output is correct
5 Correct 18 ms 3644 KB Output is correct
6 Correct 11 ms 2260 KB Output is correct
7 Correct 12 ms 2400 KB Output is correct
8 Correct 21 ms 4688 KB Output is correct
9 Correct 17 ms 2912 KB Output is correct
10 Correct 15 ms 2260 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 3016 KB Output is correct
2 Correct 25 ms 4400 KB Output is correct
3 Correct 25 ms 4044 KB Output is correct
4 Correct 10 ms 2232 KB Output is correct
5 Correct 32 ms 5568 KB Output is correct
6 Correct 35 ms 6860 KB Output is correct
7 Correct 16 ms 2900 KB Output is correct
8 Correct 19 ms 3360 KB Output is correct
9 Correct 11 ms 2264 KB Output is correct
10 Correct 12 ms 2240 KB Output is correct
11 Correct 13 ms 2236 KB Output is correct
12 Correct 13 ms 2260 KB Output is correct
13 Correct 18 ms 3624 KB Output is correct
14 Correct 11 ms 2240 KB Output is correct
15 Correct 12 ms 2388 KB Output is correct
16 Correct 27 ms 4720 KB Output is correct
17 Correct 17 ms 2900 KB Output is correct
18 Correct 11 ms 2288 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 328 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct