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 mk make_pair
#define lp(i,a,b) for(int i = a ; i < b; i++ )
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
using namespace std ;
int main(){
ios_base::sync_with_stdio(false );
cin.tie(0) ;
int N ;
cin >> N ;
vector<int> arr(N) , idx(N) ; iota(all(idx) , 0) ;
vector<int> corte(N) ;
for(auto &e : arr ) cin >> e ;
sort(all(idx),[&](int a, int b) { return arr[a] < arr[b] ; }) ;
vector<pair<int,int> > dp(N) ;
for(int i = 0 ; i < N ; i++){
if( i+1 < arr[idx[i]] ){
dp[i] = make_pair( -1 , -N-1 ) ;
continue ;
}
dp[i] = make_pair(1 , -i-1 ) ;
corte[i] = -1 ;
for(int j = i-arr[idx[i]] ; j >= 0 ; j-- ){
pair<int,int> aux = mk(dp[j].first+1 , min(dp[j].second,-(i-j)) ) ;
if(aux > dp[i]){
dp[i] = aux ;
corte[i] = j ;
}
}
}
vector< vector<int> > ans ;
int x = N-1 ;
while(x != -1){
ans.push_back(vector<int>()) ;
for(int i = corte[x]+1 ; i <= x ; i++ ) ans.back().push_back(idx[i]) ;
x = corte[x] ;
}
cout << sz(ans) << "\n" ;
for(auto e : ans ){
cout << sz(e) << " " ;
for(auto ee : e ) cout << ee+1 << " " ;
cout << "\n" ;
}
}
# | 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... |