답안 #927077

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
927077 2024-02-14T08:35:52 Z vjudge1 Martian DNA (BOI18_dna) C++17
68 / 100
2000 ms 34640 KB
/*
no more temmy :(
*/

#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
// #include<icecream.hpp>
// using namespace icecream;
#define ll long long
#define int ll
#define ld long double
#define y1 cheza
// mt19937 rng(1983413);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const int N=2e5+100;
const int M=1e3+1;
const int B=317;
const int mod=1e9+7;
const int INF=1e18;
const int lg=64;
const int dx[]={1,-1,0,0};
const int dy[]={0,0,1,-1};
const double eps=1e-9;
int n,k,rr;
int a[N];
int b[N],q[N];
bool bad(){
    map<int,int>cnt;
    for(int i=1;i<=n;i++){
        cnt[a[i]]++;
    }
    for(int i=1;i<=rr;i++){
        if(cnt[b[i]]<q[i]){
            return 1;
        }
    }
    return 0;
}
void mem(){
    map<int,int>m;
    for(int i=1;i<=n;i++){
        m[a[i]]=0;
    }
    for(int i=1;i<=rr;i++){
        m[b[i]]=i;
    }
    for(int i=1;i<=n;i++){
        a[i]=m[a[i]];
    }
    for(int i=1;i<=rr;i++){
        b[i]=m[b[i]];
    }
}
int pref[N][11];
bool check(int l,int r){
    for(int i=1;i<=rr;i++){
        int cnt=pref[r][b[i]]-pref[l-1][b[i]];
        if(cnt<q[i])return 0;
    }    
    return 1;
}
void test(){
    cin>>n>>k>>rr;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=rr;i++){
        cin>>b[i]>>q[i];
    }
    if(bad()){
        cout<<"impossible\n";
        return;
    }
    int ans=INF;
    mem();
    for(int i=1;i<=n;i++){
        for(int j=1;j<=rr;j++){
            pref[i][j]=pref[i-1][j];
        }
        pref[i][a[i]]++;
    }
    for(int i=1;i<=n;i++){
        int l=i;
        int r=n;
        if(check(i,n)==0)break;
        while(l<=r){
            int mid=(l+r)>>1ll;
            if(check(i,mid)){
                r=mid-1;
            }
            else{
                l=mid+1;
            }
        }
        r++;
        ans=min(ans,r-i+1);
        
    }
    cout<<ans<<'\n';

}
/*
*/  
 
signed main(){

    // ic.prefix("debug->| ");
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // cout.tie(nullptr);
    long long t2=1;
    //  cin>>t2;
    for(int i=1;i<=t2;i++){
        test();
    }
    
    return 0;
 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 3 ms 7004 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 1 ms 4600 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 22360 KB Output is correct
2 Correct 21 ms 22364 KB Output is correct
3 Correct 47 ms 22608 KB Output is correct
4 Correct 32 ms 22364 KB Output is correct
5 Correct 138 ms 27220 KB Output is correct
6 Correct 21 ms 22248 KB Output is correct
7 Correct 15 ms 5724 KB Output is correct
8 Correct 258 ms 34640 KB Output is correct
9 Correct 88 ms 22676 KB Output is correct
10 Correct 35 ms 22184 KB Output is correct
11 Correct 1 ms 6748 KB Output is correct
12 Correct 2 ms 6744 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 3 ms 7004 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 2 ms 6748 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4440 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2031 ms 15068 KB Time limit exceeded
2 Halted 0 ms 0 KB -