# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
754045 | HoriaHaivas | Martian DNA (BOI18_dna) | C++14 | 34 ms | 4680 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.
/*
"TLE is like the wind, always by my side"
- Yasuo - 2022 -
*/
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
#pragma GCC optimize("Ofast")
using namespace std;
int need[200001];
bool req[200001];
int f[200001];
int v[200001];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,k,r,i,j,required,pointerdr,pointerst,x,y,mi;
bool first;
cin >> n >> k >> r;
for (i=1; i<=n; i++)
{
cin >> v[i];
}
for (i=1; i<=r; i++)
{
cin >> x >> y;
need[x]=y;
req[x]=1;
}
pointerst=1;
pointerdr=1;
required=0;
mi=n+1;
first=true;
while (pointerdr<=n)
{
if (first==false)
{
f[v[pointerst]]--;
if (f[v[pointerst]]==need[v[pointerst]]-1)
required--;
pointerst++;
}
first=false;
while (required<r && pointerdr<=n)
{
f[v[pointerdr]]++;
if (f[v[pointerdr]]==need[v[pointerdr]])
required++;
pointerdr++;
}
while (required>=r)
{
f[v[pointerst]]--;
if (f[v[pointerst]]==need[v[pointerst]]-1)
required--;
pointerst++;
}
pointerst--;
f[v[pointerst]]++;
if (f[v[pointerst]]==need[v[pointerst]])
required++;
if (required==r)
mi=min(mi,pointerdr-pointerst);
}
if (mi!=n+1)
cout << mi;
else
cout << "impossible";
}
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... |