Submission #1049120

#TimeUsernameProblemLanguageResultExecution timeMemory
1049120vjudge1 Martian DNA (BOI18_dna)C++17
0 / 100
163 ms14420 KiB
#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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...