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>
using namespace std;
typedef long long ll;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<array<int,2>> a(n+1,{0,0});
for(int i=1;i<=n;i++)
{
cin >> a[i][0];
a[i][1]=i;
}
sort(a.begin(),a.end());
vector<int> p(n+1,0);
auto go=[&](int lim)->int
{
vector<int> dp(n+1,-1);
dp[0]=0;
vector<int> prv(n+1,0);
int mx=0;
for(int i=1;i<=n;i++)
{
prv[i]=prv[i-1];
if(a[i][0]>i) continue;
int j=prv[i-a[i][0]];
if(i-lim<=j&&((i<n&&dp[j]+1>=mx)||i==n))
{
dp[i]=dp[j]+1;
mx=dp[i];
prv[i]=i;
p[i]=j;
}
}
return dp[n];
};
int cnt=go(n);
int l=0,r=n;
while(l<r-1)
{
int m=(l+r)/2;
if(go(m)==cnt) r=m;
else l=m;
}
cout << cnt << "\n";
go(r);
int idx=n;
while(idx>=1)
{
cout << idx-p[idx] << " ";
for(int i=p[idx]+1;i<=idx;i++) cout << a[i][1] << " \n"[i==idx];
idx=p[idx];
}
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... |