Submission #441632

# Submission time Handle Problem Language Result Execution time Memory
441632 2021-07-05T15:28:41 Z Haruto810198 Martian DNA (BOI18_dna) C++17
100 / 100
43 ms 6724 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define double long double
 
#define FOR(i, l, r, d) for(int i=(l); i<=(r); i+=(d))
#define szof(x) ((int)(x).size())
 
#define vi vector<int>
#define pii pair<int,int>
 
#define pb push_back
#define eb emplace_back
#define mkp make_pair
 
const int INF = 2147483647;
const int LNF = INF*INF;
const int MOD = 1000000007;
const int mod = 998244353;
 
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
 
const int MAX = 200010;
 
int n, k, r;
 
int arr[MAX];
int cnt[MAX];
int req[MAX];
int sat;
 
int lptr, rptr;
 
int res;
 
signed main(){
 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    cin>>n>>k>>r;
 
    FOR(i, 1, n, 1){
        cin>>arr[i];
    }
 
    FOR(i, 1, r, 1){
        int type;
        cin>>type;
        cin>>req[type];
    }
 
    res = INF;
    lptr = 1, rptr = 0;
    sat = 0;
    int type;
 
    while(lptr <= n){
 
        while(sat < r){
            rptr++;
            if(rptr > n) break;
 
            type = arr[rptr];
            cnt[type]++;
            if(cnt[type] == req[type]){
                sat++;
            }
        }
 
        if(rptr > n) break;
 
        res = min(res, rptr - lptr + 1);
 
        //cerr<<"["<<lptr<<", "<<rptr<<"]"<<endl;
 
        type = arr[lptr];
        if(cnt[type] == req[type]){
            sat--;
        }
        cnt[type]--;
        lptr++;
 
    }
 
    if(res == INF){
        cout<<"impossible"<<'\n';
    }
    else{
        cout<<res<<'\n';
    }
 
    return 0;
 
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 2252 KB Output is correct
2 Correct 17 ms 2216 KB Output is correct
3 Correct 18 ms 2252 KB Output is correct
4 Correct 17 ms 2252 KB Output is correct
5 Correct 22 ms 3660 KB Output is correct
6 Correct 16 ms 2252 KB Output is correct
7 Correct 17 ms 2380 KB Output is correct
8 Correct 25 ms 4648 KB Output is correct
9 Correct 22 ms 2884 KB Output is correct
10 Correct 17 ms 2288 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 4804 KB Output is correct
2 Correct 33 ms 4368 KB Output is correct
3 Correct 27 ms 4020 KB Output is correct
4 Correct 16 ms 2248 KB Output is correct
5 Correct 40 ms 5572 KB Output is correct
6 Correct 43 ms 6724 KB Output is correct
7 Correct 21 ms 3012 KB Output is correct
8 Correct 25 ms 3368 KB Output is correct
9 Correct 17 ms 2356 KB Output is correct
10 Correct 17 ms 2200 KB Output is correct
11 Correct 18 ms 2252 KB Output is correct
12 Correct 17 ms 2244 KB Output is correct
13 Correct 22 ms 3660 KB Output is correct
14 Correct 16 ms 2212 KB Output is correct
15 Correct 17 ms 2372 KB Output is correct
16 Correct 25 ms 4692 KB Output is correct
17 Correct 20 ms 2948 KB Output is correct
18 Correct 19 ms 2220 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 424 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 0 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct