Submission #382476

# Submission time Handle Problem Language Result Execution time Memory
382476 2021-03-27T12:06:32 Z vishesh312 Martian DNA (BOI18_dna) C++17
0 / 100
43 ms 2028 KB
#include "bits/stdc++.h"
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
*/

#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()

using ll = long long;
const int mod = 1e9+7;

void solve(int tc) {
    int n, k, r;
    cin >> n >> k >> r;
    vector<int> v(n), a(k);
    vector<bool> need(k);
    for (auto &x : v) cin >> x;
    int req = 0;
    while (r--) {
        int b, q;
        cin >> b >> q;
        a[b] = q;
        req += q;
        need[b] = true;
    }
    int l = 0;
    r = 0;
    if (need[v[0]]) {
        --req;
    }
    --a[v[0]];
    int ans = 1e9;
    while (r < n-1) {
        while (!req) {
//          cout << "l r : " << l << " " << r << '\n';
            ans = min(ans, r-l+1);
            if (need[v[l]]) {
//              cout << "v[l] a[v[l]] : " << v[l] << " " << a[v[l]] << '\n';
                a[v[l]]++;
                if (a[v[l]] > 0) req++;
            }
            ++l;
        }
        while (req and r < n-1) {
            ++r;
            if (need[v[r]]) {
//              cout << "v[r] a[v[r]] " << v[r] << " " << a[v[r]] << '\n';
                if (a[v[r]] > 0) --req;
                a[v[r]]--;
//              cout << "a[v[r]] : " << a[v[r]] << '\n';
            }
        }
    }
    if (ans == 1e9) cout << "impossible\n";
    else cout << ans << '\n';
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int tc = 1;
    //cin >> tc;
    for (int i = 1; i <= tc; ++i) solve(i);
    return 0;
}

# 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 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 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 492 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Incorrect 1 ms 364 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 1132 KB Output is correct
2 Correct 16 ms 1132 KB Output is correct
3 Correct 16 ms 1132 KB Output is correct
4 Correct 15 ms 1132 KB Output is correct
5 Correct 19 ms 1388 KB Output is correct
6 Incorrect 14 ms 1132 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 1536 KB Output is correct
2 Correct 30 ms 1388 KB Output is correct
3 Correct 27 ms 1388 KB Output is correct
4 Correct 16 ms 1132 KB Output is correct
5 Correct 35 ms 1516 KB Output is correct
6 Correct 43 ms 2028 KB Output is correct
7 Correct 19 ms 1132 KB Output is correct
8 Correct 23 ms 1132 KB Output is correct
9 Correct 14 ms 1132 KB Output is correct
10 Correct 18 ms 1132 KB Output is correct
11 Correct 17 ms 1132 KB Output is correct
12 Correct 20 ms 1132 KB Output is correct
13 Correct 19 ms 1388 KB Output is correct
14 Incorrect 14 ms 1132 KB Output isn't correct
15 Halted 0 ms 0 KB -