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;
using lol=long long int;
#define endl "\n"
const lol mod1=1e9+7,mod2=998244353,mod3=100000000000000003,hashpr=31;
const lol inf=9e18+8;
const double eps=1e-12;
const double PI=acos(-1.0);
const int N=1e5+5;
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using ordered_set_type=lol;
typedef tree<ordered_set_type,null_type,less<ordered_set_type>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int _=1;
//cin>>_;
while(_--)
{
int n;
cin>>n;
vector<pair<int,int>> a(n);
for(int i=0;i<n;i++){
cin>>a[i].first;
a[i].second=i+1;
}
sort(a.begin(),a.end());
//dp[i]=1+max(dp[j]) st j<=i-a[i]
vector<int> dp(n+1,-1),dpmx(n+1,-1),dpargmx(n+1,-1),prev(n+1,-1);
dp[0]=0;
dpmx[0]=0;
dpargmx[0]=0;
prev[0]=-1;
for(int i=1;i<=n;i++){
int j=i-a[i-1].first;
if(j>=0){
dp[i]=1+dpmx[j];
prev[i]=dpargmx[j];
}
if(dp[i]>=dpmx[i-1]){
dpmx[i]=dp[i];
dpargmx[i]=i;
}else{
dpmx[i]=dpmx[i-1];
dpargmx[i]=dpargmx[i-1];
}
}
vector<int> v;
int p=n;
while(p>0){
v.push_back(p);
p=prev[p];
}
cout<<dp[n]<<endl;
v.push_back(0);
for(auto& e:v) e--;
reverse(v.begin(),v.end());
for(int i=0;i<v.size()-1;i++){
cout<<v[i+1]-v[i]<<" ";
for(int j=v[i]+1;j<=v[i+1];j++){
cout<<a[j].second<<" ";
}
cout<<endl;
}
}
return 0;
}
Compilation message (stderr)
tea.cpp: In function 'int main()':
tea.cpp:63:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for(int i=0;i<v.size()-1;i++){
| ~^~~~~~~~~~~
# | 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... |