# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
668579 | ktkerem | Martian DNA (BOI18_dna) | C++11 | 52 ms | 6916 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
#include<bits/stdc++.h>
/**/
//typedef int ll;
typedef long long ll;
typedef unsigned long long ull;
typedef std::string str;
//typedef vector<std::vector<ll>> vv;
/*typedef __int128 vll;
typedef unsigned __int128 uvll;*/
#define llll std::pair<ll , ll>
#define pb push_back
#define pf push_front
#define halo cout << "hello\n"
#define fi first
#define sec second
#define vv(x) std::vector<std::vector<x>>
#define all(a) a.begin() , a.end()
const ll limit = 1e15+7;
const ll ous = 3e5 + 7;
const ll dx[4] = {-1 , 0 , 1 , 0} , dy[4] = {0,1,0,-1};
ll n , m , k;std::vector<ll> ar;
std::vector<ll> kt;
ll tot = 0;
ll fd(ll sz){
std::vector<ll> vt(m+5 , 0);
ll p = 0;
for(ll i = 0;sz>i;i++){
if(kt[ar[i]] > vt[ar[i]]){
p++;
}
vt[ar[i]]++;
}
if(p == tot){
return 1;
}
for(ll i = sz;n>i;i++){
if(kt[ar[i]] > vt[ar[i]]){
p++;
}
vt[ar[i]]++;
if(kt[ar[i-sz]] >= vt[ar[i-sz]]){
p--;
}
vt[ar[i - sz]]--;
if(p == tot){
return 1;
}
}
if(p == tot){
return 1;
}
return 0;
}
void solve(){
std::cin >> n >> m >> k;
kt.resize(m+5 , 0);
ar.resize(n);
for(ll i = 0;n>i;i++){
std::cin >> ar[i];
}
for(ll i = 0;k>i;i++){
ll x , y;std::cin >> x >> y;
kt[x]+=y;
tot+=y;
}
ll l = 1 , r = n+1;
while(r > l){
ll md = (r + l)/2;
if(fd(md)){
r = md;
}
else{
l = md + 1;
}
}
if(l == n+1){
std::cout << "impossible\n";
return;
}
std::cout << l << "\n";
return;/**/
}
signed main(){
std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);
ll t=1;
//std::cin >> t;
ll o = 1;
while(t--){
//cout << "Case " << o++ << ":\n";
solve();
}
return 0;
}/**/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |