이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
/*
Lift
ST3-6 are split up into half-subtasks
ST2.5-5.5: simple DP?
5000ms time limit;
20p with brute force O((n/2)^5)
2:56 pm
ST1/2: plain brute force (O(M*(sum(a_l)^2)) = O(n^5))
*/
std::vector<int> uplifts;
int main(){
int m;
long long l;
std::cin>>m>>l;
int maxv=0;
for(int i=-m;i<=m;i++){
int x;
std::cin>>x;
uplifts.push_back(x);
maxv=std::max(x,maxv);
}
if(m*m*maxv*maxv<=100000000){
int tmv=m*(m+1)/2*maxv+1;//really only half of the max
std::vector<int> values1(tmv,-1000000000);//positive
std::vector<int> values2(tmv,-1000000000);//negative
values1[0]=0;
values2[0]=0;
for(int k=1;k<=m;k++){
for(int x=0;x<uplifts[m+k];x++){
for(int y=tmv-1-k;y>=0;y--){
values1[y+k]=std::max(values1[y]+1,values1[y+k]);
}
}
}
for(int k=1;k<=m;k++){
for(int x=0;x<uplifts[m-k];x++){
for(int y=tmv-1-k;y>=0;y--){
values2[y+k]=std::max(values2[y]+1,values2[y+k]);
}
}
}
int totalmax=-1;
for(int i=0;i<tmv&&i-l<tmv;i++){
if(i-l<0)continue;
totalmax=std::max(totalmax,values1[i]+values2[i-l]);
}
if(totalmax<0){
std::cout<<"impossible\n";
}else{
std::cout<<totalmax+uplifts[m]<<'\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... |