Submission #535878

#TimeUsernameProblemLanguageResultExecution timeMemory
535878inksamuraiVolontiranje (COCI21_volontiranje)C++17
50 / 110
1083 ms7952 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) #define rng(i,x,n) for(int i=x;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define fi first #define se second #define pb push_back #define sz(a) (int)a.size() #define vec(...) vector<__VA_ARGS__> #define _3HspL4A ios::sync_with_stdio(0),cin.tie(0) typedef long long ll; using pii=pair<int,int>; using vi=vec(int); void print(){cout<<"\n";} template<class T,class...E> void print(const T&v,const E&...u){cout<<v<<' ',print(u...);} // e signed main(){ _3HspL4A; int n; cin>>n; vi a(n); rep(i,n){ cin>>a[i]; } set<int> st; for(auto x:a){ if(!sz(st)){ st.insert(x); }else{ auto it=st.lower_bound(x); if(it!=st.end()){ st.erase(it); } st.insert(x); } } int len=sz(st); vi usd(n); vec(vi) pns; while(1){ int n=sz(a),pok=0; vi dp(n); for(int i=0;i<n;i++){ if(usd[i]) continue; dp[i]=1; for(int j=0;j<i;j++){ if(usd[j]) continue; if(a[i]>a[j]){ dp[i]=max(dp[i],dp[j]+1); } } if(dp[i]==len){ pok=1; pns.pb({}); int now=len,pj=i; while(1){ int nj=-1,v=-1; for(int j=i;j>=0;j--){ if(usd[j]) continue; if(dp[j]==now and a[pj]>=a[j]){ if(a[j]>v){ v=a[j]; nj=j; } } } pns.back().pb(nj); pj=nj; now--; if(!now) break; } for(auto ids:pns.back()){ usd[ids]=1; } break; } } if(!pok) break; } print(sz(pns),len); for(auto ids:pns){ reverse(ids.begin(),ids.end()); for(auto v:ids) cout<<v+1<<" "; print(); } // return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...