이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<cstdio>
#include<map>
#include<vector>
#include<math.h>
#include<cstdlib>
#include<algorithm>
using namespace std;
int n,l;
long long int dp[100001][2];
long long int cal1,cal2;
int upper[100001],ucnt;
int lower[100001],lcnt;
map<int,int> upmap;
map<int,int> downmap;
class link{
public:
int up,down,dist;
bool operator < (const link &l) const{
if(up==l.up) return down < l.down;
else return up < l.up;
}
}line[100002];
int main(){
int i;
long long int cal1,cal2,mx=0;
scanf("%d %d",&n,&l);
for(i=0;i<n;i++){
scanf("%d %d",&(line[i].up),&(line[i].down));
line[i].dist=l+abs(line[i].up-line[i].down);
if(upmap[line[i].up]==0){
upmap[line[i].up]=-1;
upper[ucnt++]=line[i].up;
}
if(downmap[line[i].down]==0){
downmap[line[i].down]=-1;
lower[lcnt++]=line[i].down;
}
}
sort(upper,upper+ucnt);
sort(lower,lower+lcnt);
for(i=0;i<ucnt;i++){
upmap[upper[i]]=i;
}
for(i=0;i<lcnt;i++){
downmap[lower[i]]=i;
}
for(i=0;i<n;i++){
line[i].up=upmap[line[i].up];
line[i].down=downmap[line[i].down];
}
sort(line,line+n);
for(i=0;i<n;i++){
cal1=line[i].dist+dp[line[i].up][0];
cal2=line[i].dist+dp[line[i].down][1];
dp[line[i].up][0]=max(dp[line[i].up][0],cal2);
dp[line[i].down][1]=max(dp[line[i].down][1],cal1);
}
for(i=0;i<n;i++){
mx=max(mx,dp[i][0]);
mx=max(mx,dp[i][1]);
}
printf("%lld",mx);
}
# | 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... |