This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<iostream>
#include<algorithm>
using namespace std;
int Prv[1000005],Best[1000005],Dp[1000005];
pair<int,int> A[1000005];
int n,opt;
//nu era corecta solutia precedenta deoarece se putea sa fie mai bine sa extind echipa curenta pt a scadea lungimea precedentei
bool check(int lgmax)
{
Dp[0]=0;
Best[0]=0;
for(int i=1; i<=n; i++)
{
Best[i]=Best[i-1];
if(i<A[i].first)
{
Dp[i]=-1000000000;
continue;
}
if(Best[i-A[i].first]>=i-lgmax)
{
Dp[i]=1+Dp[Best[i-A[i].first]];
Prv[i]=Best[i-A[i].first];
if(Dp[i]>=Dp[Best[i]])
Best[i]=i;
}
else
Dp[i]=-1000000000;
}
return (Dp[n]==opt);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1; i<=n; i++)
{
cin>>A[i].first;
A[i].second=i;
}
sort(A+1,A+n+1); //pax din echipe o sa fie pe pozitii consecutive
check(n);
opt=Dp[n];
int lung=0;
for(int i=19; i>=0; i--)
{
if(!check(lung+(1<<i)))
lung+=(1<<i);
}
check(lung+1);
cout<<Dp[n]<<"\n";
int poz=n;
while(poz!=0)
{
cout<<poz-Prv[poz]<<" ";
for(int i=poz; i>Prv[poz]; i--)
cout<<A[i].second<<" ";
cout<<"\n";
poz=Prv[poz];
}
return 0;
}
# | 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... |
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |