Submission #448549

#TimeUsernameProblemLanguageResultExecution timeMemory
448549Edbert2397 Martian DNA (BOI18_dna)C++14
100 / 100
72 ms4476 KiB
/* ~2021~ */ # include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define fi first #define se second typedef long long ll; #define pii pair<int,int> #define debug(x) cout << #x << '=' << x << endl; const int N = 2e5 + 5; const int INF = 1e9; const ll mod = 1e9+7; int need[N],arr[N],n,k,q,byk[N]; bool valid(int x){ for(int i = 0;i<k;i++) byk[i] = 0; int cnt = 0; for(int i = 1;i<=n;i++){ if(i > x){ if(byk[arr[i-x]] == need[arr[i-x]]) cnt--; byk[arr[i-x]]--; } byk[arr[i]]++; if(byk[arr[i]] == need[arr[i]]) cnt++; if(cnt == q) return true; } return false; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //freopen(,r,stdin); //freopen(,w,stdout); cin>>n>>k>>q; for(int i = 1;i<=n;i++) cin>>arr[i]; for(int i = 1;i<=q;i++){ int x,y; cin>>x>>y; need[x] = y; } int ki = 1,ka = n; int pos = -1; while(ki <= ka){ int mid = (ki + ka)/2; if(valid(mid)){ pos = mid; ka = mid-1; } else{ ki = mid + 1; } } if(pos == -1) cout<<"impossible"<<endl; else cout<<pos<<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...