답안 #1049120

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1049120 2024-08-08T13:36:58 Z vjudge1 Martian DNA (BOI18_dna) C++17
0 / 100
163 ms 14420 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 l=1;
    ll r=n;
    while(l<r){
        if(cnt[a[r]]>nd[a[r]]){
            cnt[a[r]]--;
            r--;
        }
        else if(cnt[a[l]]>nd[a[l]]){
            cnt[a[l]]--;
            l++;
        }
        else{
            break;
        }
    }
    cout<<r-l+1<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 2908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 163 ms 14420 KB Output isn't correct
2 Halted 0 ms 0 KB -