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 <iostream>
#include <vector>
#include <set>
using namespace std;
int main(){
int n,x,maxi=0,maxi2;
cin>>n>>x;
vector<int>list(n);
for(int i=0;i<n;i++){
cin>>list[i];
}
vector<vector<pair<int,set<int> > > >DP(n,vector<pair<int,set<int> > >(n));
vector<bool> visto(n,false);
pair<int,set<int> > maximo;
for(int i=0;i<n;i++){
if(visto[i])continue;
DP[i][i].first=list[i];
DP[i][i].second.insert(i);
maximo=DP[i][i];
for(int j=i+1;j<n;j++){
if(visto[j])continue;
for(int q=i;q<j;q++){
if(list[j]>DP[i][q].first&&DP[i][q].second.size()+1>DP[i][j].second.size()){
DP[i][j]=DP[i][q];
DP[i][j].first=list[j];
DP[i][j].second.insert(j);
if(DP[i][j].second.size()>maximo.second.size())maximo=DP[i][j];
}
}
if(DP[i][j].first==0)DP[i][j]=maximo;
}
int t=maximo.second.size();
if(t>maxi)maxi=t;
else if(t>maxi2)maxi2=t;
for(auto it=maximo.second.begin();it!=maximo.second.end();it++){
visto[*it]=true;
}
}
cout<<maxi+maxi2;
}
Compilation message (stderr)
glo.cpp: In function 'int main()':
glo.cpp:39:13: warning: 'maxi2' may be used uninitialized in this function [-Wmaybe-uninitialized]
39 | cout<<maxi+maxi2;
| ^~~~~
# | 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... |