답안 #939503

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
939503 2024-03-06T12:22:36 Z 12345678 Martian DNA (BOI18_dna) C++17
100 / 100
108 ms 16620 KB
#include <bits/stdc++.h>

using namespace std;

const int nx=2e5+5;
int n, v[nx], k, r, res[nx], b, q, ans=INT_MAX;
vector<int> d[nx];

struct segtree
{
    int d[4*nx];
    void update(int l, int r, int i, int ql, int qr, int vl)
    {
        if (qr<l||r<ql||r<l) return;
        if (ql<=l&&r<=qr) return d[i]=min(d[i], vl), void();
        int md=(l+r)/2;
        update(l, md, 2*i, ql, qr, vl);
        update(md+1, r, 2*i+1, ql, qr, vl);
    }
    void solve(int l, int r, int i)
    {
        if (d[i]==INT_MIN) return;
        if (l==r) return ans=min(ans, l-d[i]+1), void();
        d[2*i]=min(d[2*i], d[i]);
        d[2*i+1]=min(d[2*i+1], d[i]);
        int md=(l+r)/2;
        solve(l, md, 2*i);
        solve(md+1, r, 2*i+1);
    }
} s;

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>k>>r;
    for (int i=1; i<=n; i++) cin>>v[i], d[v[i]].push_back(i);
    for (int i=1; i<4*nx; i++) s.d[i]=INT_MAX;
    for (int i=1; i<=r; i++)
    {
        cin>>b>>q;
        d[b].push_back(n+1);
        if ((int) d[b].size()<q-1) return cout<<"impossible", 0;
        s.update(1, n, 1, 1, d[b][q-1]-1, INT_MIN);
        for (int j=q; j<(int)d[b].size(); j++) s.update(1, n, 1, d[b][j-1], d[b][j]-1, d[b][j-q]);
        //s.solve(1, n, 1);
    }
    s.solve(1, n , 1);
    if (ans==INT_MAX) cout<<"impossible";
    else cout<<ans;
}

/*
10 2 2
0 0 1 0 0 0 0 1 0 0
1 2
0 2

10 2 2
0 0 1 0 0 0 0 1 0 0
1 1
0 2

10 2 2
0 0 1 0 0 0 0 1 0 0
0 2
1 2
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8804 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 3 ms 8796 KB Output is correct
4 Correct 3 ms 8796 KB Output is correct
5 Correct 2 ms 8632 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 3 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8792 KB Output is correct
2 Correct 3 ms 8796 KB Output is correct
3 Correct 3 ms 8884 KB Output is correct
4 Correct 3 ms 8796 KB Output is correct
5 Correct 3 ms 8796 KB Output is correct
6 Correct 3 ms 8796 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 8796 KB Output is correct
11 Correct 3 ms 8796 KB Output is correct
12 Correct 2 ms 8796 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
14 Correct 2 ms 8796 KB Output is correct
15 Correct 2 ms 8632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 10844 KB Output is correct
2 Correct 23 ms 10772 KB Output is correct
3 Correct 34 ms 10456 KB Output is correct
4 Correct 27 ms 10800 KB Output is correct
5 Correct 22 ms 12180 KB Output is correct
6 Correct 11 ms 10716 KB Output is correct
7 Correct 16 ms 10584 KB Output is correct
8 Correct 39 ms 15716 KB Output is correct
9 Correct 23 ms 10836 KB Output is correct
10 Correct 27 ms 10744 KB Output is correct
11 Correct 2 ms 8796 KB Output is correct
12 Correct 3 ms 9044 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
14 Correct 2 ms 8796 KB Output is correct
15 Correct 3 ms 8720 KB Output is correct
16 Correct 3 ms 8796 KB Output is correct
17 Correct 2 ms 8796 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 3 ms 8796 KB Output is correct
20 Correct 2 ms 8796 KB Output is correct
21 Correct 2 ms 8796 KB Output is correct
22 Correct 3 ms 8672 KB Output is correct
23 Correct 2 ms 8792 KB Output is correct
24 Correct 2 ms 8796 KB Output is correct
25 Correct 2 ms 8796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 108 ms 12124 KB Output is correct
2 Correct 100 ms 11668 KB Output is correct
3 Correct 51 ms 11496 KB Output is correct
4 Correct 28 ms 10480 KB Output is correct
5 Correct 25 ms 12624 KB Output is correct
6 Correct 94 ms 16468 KB Output is correct
7 Correct 53 ms 11820 KB Output is correct
8 Correct 69 ms 11864 KB Output is correct
9 Correct 22 ms 11608 KB Output is correct
10 Correct 28 ms 11028 KB Output is correct
11 Correct 33 ms 10968 KB Output is correct
12 Correct 35 ms 11316 KB Output is correct
13 Correct 35 ms 12988 KB Output is correct
14 Correct 13 ms 11100 KB Output is correct
15 Correct 16 ms 11028 KB Output is correct
16 Correct 40 ms 16620 KB Output is correct
17 Correct 19 ms 11608 KB Output is correct
18 Correct 33 ms 10912 KB Output is correct
19 Correct 3 ms 8796 KB Output is correct
20 Correct 3 ms 9216 KB Output is correct
21 Correct 2 ms 8796 KB Output is correct
22 Correct 2 ms 8796 KB Output is correct
23 Correct 2 ms 8796 KB Output is correct
24 Correct 4 ms 8796 KB Output is correct
25 Correct 2 ms 8792 KB Output is correct
26 Correct 2 ms 9048 KB Output is correct
27 Correct 2 ms 8624 KB Output is correct
28 Correct 3 ms 8660 KB Output is correct
29 Correct 2 ms 8792 KB Output is correct
30 Correct 2 ms 8796 KB Output is correct
31 Correct 2 ms 8668 KB Output is correct
32 Correct 3 ms 8796 KB Output is correct
33 Correct 2 ms 8796 KB Output is correct