답안 #4464

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
4464 2013-10-07T15:06:51 Z model_code 막대기 (KOI13_game) C++
100 / 100
100 ms 4996 KB
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;

const int N=111111;
struct Stick{int t,d,s;};
int n,l;
Stick a[N]; 
int t_x[N],d_x[N];
long long e[N][2],v1,v2,ans;

int cmp(const Stick &p,const Stick &q){return p.t<q.t||(p.t==q.t&&p.d<q.d);}

int main()
{
	int i,v;

	scanf("%d%d",&n,&l);
	for(i=0;i<n;++i)
	{
		scanf("%d%d",&a[i].t,&a[i].d);
		a[i].s=abs(a[i].t-a[i].d)+l;
		t_x[i]=a[i].t;
		d_x[i]=a[i].d;
	}
	sort(t_x,t_x+n);
	sort(d_x,d_x+n);
	for(i=0;i<n;++i)
	{
		a[i].t=lower_bound(t_x,t_x+n,a[i].t)-t_x;
		a[i].d=lower_bound(d_x,d_x+n,a[i].d)-d_x;
	}
	sort(a,a+n,cmp);
	
	for(i=0;i<n;++i)
	{
		v1=e[a[i].t][0]+a[i].s;
		v2=e[a[i].d][1]+a[i].s;
		if(v1>e[a[i].d][1]) e[a[i].d][1]=v1;
		if(v2>e[a[i].t][0]) e[a[i].t][0]=v2;
		if(v1>ans) ans=v1;
		if(v2>ans) ans=v2;
	}
	printf("%lld\n",ans);
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4996 KB Output is correct
2 Correct 0 ms 4996 KB Output is correct
3 Correct 0 ms 4996 KB Output is correct
4 Correct 0 ms 4996 KB Output is correct
5 Correct 0 ms 4996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 4996 KB Output is correct
2 Correct 36 ms 4996 KB Output is correct
3 Correct 88 ms 4996 KB Output is correct
4 Correct 72 ms 4996 KB Output is correct
5 Correct 80 ms 4996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4996 KB Output is correct
2 Correct 0 ms 4996 KB Output is correct
3 Correct 0 ms 4996 KB Output is correct
4 Correct 0 ms 4996 KB Output is correct
5 Correct 0 ms 4996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4996 KB Output is correct
2 Correct 0 ms 4996 KB Output is correct
3 Correct 0 ms 4996 KB Output is correct
4 Correct 0 ms 4996 KB Output is correct
5 Correct 0 ms 4996 KB Output is correct
6 Correct 0 ms 4996 KB Output is correct
7 Correct 0 ms 4996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 4996 KB Output is correct
2 Correct 8 ms 4996 KB Output is correct
3 Correct 40 ms 4996 KB Output is correct
4 Correct 92 ms 4996 KB Output is correct
5 Correct 88 ms 4996 KB Output is correct
6 Correct 80 ms 4996 KB Output is correct
7 Correct 100 ms 4996 KB Output is correct
8 Correct 76 ms 4996 KB Output is correct
9 Correct 8 ms 4996 KB Output is correct
10 Correct 8 ms 4996 KB Output is correct
11 Correct 96 ms 4996 KB Output is correct
12 Correct 96 ms 4996 KB Output is correct