# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
20431 | CodingBug (#35) | Can polan into space? (OJUZ11_space) | C++98 | 129 ms | 9052 KiB |
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 M 200000
using namespace std;
int d[M+1][2],n,a[M+1][3];
int p[M+1][2],l,r,ans[M*2+1];
void input(void){
int i;
scanf("%d",&n);
for(i=1;i<=n;i++) scanf("%d %d %d",&a[i][0],&a[i][1],&a[i][2]);
}
void process(void){
int i,j;
d[1][0]=-1e9;
d[1][1]=0;
for(i=2;i<=n;i++){
int lf=d[i-1][0]+a[i-1][1],rf=d[i-1][1]+a[i-1][0];
if(lf>rf){
d[i][0]=lf;
p[i][0]=0;
}else{
d[i][0]=rf;
p[i][0]=1;
}
lf=d[i-1][0]+a[i-1][2],rf=d[i-1][1]+a[i-1][1];
if(lf>rf){
d[i][1]=lf;
p[i][1]=0;
}else{
d[i][1]=rf;
p[i][1]=1;
}
}
int x;
if(d[n][0]+a[n][1]>d[n][1]+a[n][0]){
printf("%d\n",d[n][0]+a[n][1]);
x=0;
}else{
printf("%d\n",d[n][1]+a[n][0]);
x=1;
}
l=r=n;
ans[n]=n;
for(i=n;i>1;i--){
if(x){
ans[++r]=i-1;
}else{
ans[--l]=i-1;
}
x=p[i][x];
}
for(i=l;i<=r;i++) printf("%d ",ans[i]);
}
int main(){
// freopen("input.txt","r",stdin);
input();
process();
return 0;
}
Compilation message (stderr)
# | 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... |