Submission #932628

# Submission time Handle Problem Language Result Execution time Memory
932628 2024-02-24T01:17:56 Z LOLOLO Martian DNA (BOI18_dna) C++17
16 / 100
89 ms 148184 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (int)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())

const int N = 1e5 + 10;
int a[N], nxt[N];
vector <int> pos[N];
deque <int> dq[N];

ll solve() {
    int n, k, num;
    cin >> n >> k >> num;

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        pos[a[i]].pb(i);
    }

    for (int i = 0; i < num; i++) {
        int b, q;
        cin >> b >> q;
        for (int j = 0; j < sz(pos[b]); j++) {
            if (j + q - 1 < sz(pos[b])) {
                nxt[pos[b][j]] = pos[b][j + q - 1];
            } else {
                nxt[pos[b][j]] = n + 1;
            }
        }
    }

    int lst = 0;
    int l = 0, r = n, m, ans = -1;
    while (l <= r) {
        m = (l + r) / 2;
        int mx = 0, cnt = 0;
        bool ch = 0;

        for (int i = 1; i <= n; i++) {
            if (nxt[i]) {
                dq[a[i]].pb(nxt[i]);
                if (sz(dq[a[i]]) == 1) {
                    cnt++;
                    mx = max(mx, nxt[i]);
                }
            }

            if (i > m) {
                dq[a[i - m]].pop_front();
                if (sz(dq[a[i - m]])) {
                    mx = max(mx, dq[a[i - m]].front());
                } else {
                    cnt--;
                }
            }

            if (mx <= i && cnt == num) {
                lst = i;
                ch = 1;
                break;
            }
        }

        for (int i = 1; i <= n; i++)
            dq[a[i]].clear();

        if (ch) {
            ans = m;
            r = m - 1;
        } else {
            l = m + 1;
        }
    }

    if (ans == -1) {
        cout << "impossible\n";
        return 0;
    }

    cout << ans << '\n';
    return 0;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    //cin >> t;

    while (t--) {
        solve();
        //cout << solve() << '\n';
    }

    return 0;
}

Compilation message

dna.cpp: In function 'll solve()':
dna.cpp:49:9: warning: variable 'lst' set but not used [-Wunused-but-set-variable]
   49 |     int lst = 0;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 30 ms 70224 KB Output is correct
2 Correct 30 ms 70372 KB Output is correct
3 Correct 30 ms 70236 KB Output is correct
4 Correct 31 ms 70228 KB Output is correct
5 Correct 36 ms 70228 KB Output is correct
6 Correct 30 ms 70236 KB Output is correct
7 Correct 30 ms 70236 KB Output is correct
8 Correct 36 ms 70228 KB Output is correct
9 Correct 31 ms 70232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 78 ms 142260 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 82 ms 144328 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 89 ms 148184 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -