Submission #1049123

# Submission time Handle Problem Language Result Execution time Memory
1049123 2024-08-08T13:39:45 Z vjudge1 Martian DNA (BOI18_dna) C++17
0 / 100
159 ms 12880 KB
#include <bits/stdc++.h>
using namespace std;
#define ll  long long
#define fi first
#define se second
#define sst string
#define pb push_back
#define maxco 100000+5
#define lld long double
#define cha ios_base::sync_with_stdio(false);
#define ffl cout.flush();
#define phi acos(-1)
#define mr make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define pqin priority_queue<ll,vector<ll>,greater<>>
#define pqpair priority_queue<pair<ll,ll> ,vector<pair<ll,ll>>,greater<pair<ll,ll>>>
#define pqpair2 priority_queue<pair<pair<ll,ll>,pair<ll,ll>>,vector<pair<pi,pair<ll,ll>>>,greater<pair<pi,pair<ll,ll>>>>
#define INF 1000000009
#define MAXN 1000006
#define pii pair<ll,ll>
 
#define mod 998244353
ll a[MAXN];
ll n,k,r;

map<ll,ll> nd;
int main(){
    cin>>n>>k>>r;
    map<ll,ll> cnt;
    REP(i,1,n){
        cin>>a[i];
        cnt[a[i]]++;
    }
    REP(i,1,r){
        ll b,c;
        cin>>b>>c;
        nd[b]=c;
    }
    REP(i,0,k){
        if(nd[i]>cnt[i]){
            cout<<"impossible"<<endl;
            return 0;
        }
    }
    ll ln=1;
    ll rn=n;
    while(ln<rn){
        if(cnt[a[rn]]>nd[a[rn]]){
            cnt[a[rn]]--;
            rn--;
        }
        else if(cnt[a[ln]]>nd[a[ln]]){
            cnt[a[ln]]--;
            ln++;
        }
        else{
            break;
        }
    }
    cout<<rn-ln+1<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 2664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 159 ms 12880 KB Output isn't correct
2 Halted 0 ms 0 KB -