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<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}
ll readint(){
ll x=0,f=1; char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,dp[1000005],prv[1000005],lst[1000005];
pii a[1000005];
int solve(int x){
for(int i=0;i<=n;i++){
dp[i]=(int)-1e9;
prv[i]=0;
}
dp[0]=lst[0]=0;
int mx=0;
for(int i=1;i<=n;i++){
lst[i]=lst[i-1];
if(a[i].fi>i) continue;
int p=lst[i-a[i].fi];
if(p>=max(0,i-x)){
dp[i]=dp[p]+1;
prv[i]=p;
if(dp[i]<mx) continue;
mx=dp[i];
lst[i]=i;
}
}
return dp[n];
}
int main(){
n=readint();
for(int i=1;i<=n;i++) a[i].fi=readint(),a[i].se=i;
sort(a+1,a+n+1);
int mx=solve(n);
int l=a[n].fi,r=n,f=n;
while(l<=r){
int mid=(l+r)/2;
if(solve(mid)==mx) f=mid,r=mid-1;
else l=mid+1;
}
solve(f);
printf("%d\n",mx);
int p=n;
while(p>0){
printf("%d ",p-prv[p]);
for(int i=prv[p]+1;i<=p;i++) printf("%d ",a[i].se);
printf("\n");
p=prv[p];
}
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... |