Submission #388416

# Submission time Handle Problem Language Result Execution time Memory
388416 2021-04-11T12:06:58 Z leaked Martian DNA (BOI18_dna) C++14
100 / 100
245 ms 25164 KB
#include <bits/stdc++.h>
#define sz(x) (int)x.size()
#define vec vector
#define pb push_back
#define rall(x) x.rbegin(),x.rend()
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define f first
#define s second
using namespace std;
typedef unsigned long long ull;
auto rnd=bind(uniform_int_distribution<long long>(1,1e18),mt19937(time(0)));

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,k,q;
    cin>>n>>k>>q;
    vec<pii>need(q);
    vec<int>a(n);
    map<int,int>mp;
    int cr=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(!mp.count(a[i])){
            mp[a[i]]=cr++;
        }
        a[i]=mp[a[i]];
    }
    for(auto &z : need){
        cin>>z.f>>z.s;
        if(!mp.count(z.f)) mp[z.f]=cr++;
        z.f=mp[z.f];
    }
    vec<int>pos(n,-1);
    vec<vec<int>>vc(cr,vec<int>());
    vec<int>last(sz(mp),-1);
    vec<int>nxt(cr,-1);
    for(auto &z : need) nxt[z.f]=z.s;
    for(int i=0;i<n;i++){
        pos[i]=sz(vc[a[i]]);
        vc[a[i]].pb(i);
    }
    for(auto &z : vc) reverse(all(z));
    int ans=2e9;
    int mx=-1;
    for(auto &z : need){
        if(sz(vc[z.f])<z.s){
            cout<<"impossible";
            return 0;
        }
        mx=max(mx,vc[z.f][sz(vc[z.f])-z.s]);
    }
    ans=min(ans,mx+1);
    for(int i=0;i<n;i++){
        int clr=a[i];
        vc[clr].pop_back();
        if(nxt[clr]!=-1){
            if(sz(vc[clr])<nxt[clr]) break;
            mx=max(mx,vc[clr][sz(vc[clr])-nxt[clr]]);
        }
        ans=min(ans,mx-i);
//        cerr<<i<<' '<<mx<<endl;
    }
    if(ans==2e9) cout<<"impossible";
    else cout<<ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 3 ms 588 KB Output is correct
4 Correct 3 ms 716 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 320 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 3596 KB Output is correct
2 Correct 20 ms 3464 KB Output is correct
3 Correct 23 ms 3336 KB Output is correct
4 Correct 23 ms 3536 KB Output is correct
5 Correct 110 ms 11936 KB Output is correct
6 Correct 22 ms 3412 KB Output is correct
7 Correct 30 ms 3476 KB Output is correct
8 Correct 199 ms 25164 KB Output is correct
9 Correct 83 ms 4788 KB Output is correct
10 Correct 29 ms 3388 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 2 ms 588 KB Output is correct
14 Correct 3 ms 716 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 155 ms 12988 KB Output is correct
2 Correct 133 ms 10732 KB Output is correct
3 Correct 133 ms 10112 KB Output is correct
4 Correct 20 ms 3440 KB Output is correct
5 Correct 191 ms 15624 KB Output is correct
6 Correct 245 ms 24476 KB Output is correct
7 Correct 72 ms 4932 KB Output is correct
8 Correct 92 ms 6340 KB Output is correct
9 Correct 24 ms 3532 KB Output is correct
10 Correct 19 ms 3452 KB Output is correct
11 Correct 24 ms 3400 KB Output is correct
12 Correct 26 ms 3528 KB Output is correct
13 Correct 110 ms 11948 KB Output is correct
14 Correct 22 ms 3420 KB Output is correct
15 Correct 29 ms 3396 KB Output is correct
16 Correct 175 ms 24980 KB Output is correct
17 Correct 67 ms 4800 KB Output is correct
18 Correct 23 ms 3404 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 3 ms 588 KB Output is correct
22 Correct 4 ms 716 KB Output is correct
23 Correct 2 ms 464 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct