# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
8237 |
2014-09-07T12:45:20 Z |
ansol4328 |
막대기 (KOI13_game) |
C++ |
|
96 ms |
4608 KB |
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#define MAXN 100005
struct Stick
{
int t, d, s;
};
Stick m[MAXN];
int cmp(const Stick &a, const Stick &b)
{
return a.t<b.t || (a.t==b.t && a.d<b.d);
}
long long dp[MAXN][2], out;
int n, h, tx[MAXN], dx[MAXN];
int bst(int x)
{
int st, fn, mid;
st=1, fn=n;
while(st<=fn)
{
mid=(st+fn)/2;
if(tx[mid]>x) fn=mid-1;
else if(tx[mid]<x) st=mid+1;
else if(tx[mid]==x) break;
}
return mid;
}
int bsd(int x)
{
int st, fn, mid;
st=1, fn=n;
while(st<=fn)
{
mid=(st+fn)/2;
if(dx[mid]>x) fn=mid-1;
else if(dx[mid]<x) st=mid+1;
else if(dx[mid]==x) break;
}
return mid;
}
void Init()
{
int i;
scanf("%d %d",&n,&h);
for(i=1 ; i<=n ; i++)
{
scanf("%d %d",&m[i].t,&m[i].d);
tx[i]=m[i].t, dx[i]=m[i].d;
m[i].s=h+abs(m[i].t-m[i].d);
}
std::sort(tx+1,tx+1+n);
std::sort(dx+1,dx+1+n);
}
void Change()
{
int i;
for(i=1 ; i<=n ; i++)
{
m[i].t=bst(m[i].t);
m[i].d=bsd(m[i].d);
}
std::sort(m+1,m+1+n,cmp);
}
void dynamic()
{
int i;
long long v1, v2;
for(i=1 ; i<=n ; i++)
{
v1=dp[m[i].t][0]+m[i].s;
v2=dp[m[i].d][1]+m[i].s;
if(dp[m[i].d][1]<v1)
{
dp[m[i].d][1]=v1;
if(out<dp[m[i].d][1]) out=dp[m[i].d][1];
}
if(dp[m[i].t][0]<v2)
{
dp[m[i].t][0]=v2;
if(out<dp[m[i].t][0]) out=dp[m[i].t][0];
}
}
}
int main()
{
Init();
Change();
dynamic();
printf("%lld",out);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
4608 KB |
Output is correct |
2 |
Correct |
0 ms |
4608 KB |
Output is correct |
3 |
Correct |
0 ms |
4608 KB |
Output is correct |
4 |
Correct |
0 ms |
4608 KB |
Output is correct |
5 |
Correct |
0 ms |
4608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
4608 KB |
Output is correct |
2 |
Correct |
32 ms |
4608 KB |
Output is correct |
3 |
Correct |
72 ms |
4608 KB |
Output is correct |
4 |
Correct |
68 ms |
4608 KB |
Output is correct |
5 |
Correct |
72 ms |
4608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
4608 KB |
Output is correct |
2 |
Correct |
0 ms |
4608 KB |
Output is correct |
3 |
Correct |
0 ms |
4608 KB |
Output is correct |
4 |
Correct |
0 ms |
4608 KB |
Output is correct |
5 |
Correct |
0 ms |
4608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
4608 KB |
Output is correct |
2 |
Correct |
0 ms |
4608 KB |
Output is correct |
3 |
Correct |
0 ms |
4608 KB |
Output is correct |
4 |
Correct |
0 ms |
4608 KB |
Output is correct |
5 |
Correct |
0 ms |
4608 KB |
Output is correct |
6 |
Correct |
0 ms |
4608 KB |
Output is correct |
7 |
Correct |
0 ms |
4608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
4608 KB |
Output is correct |
2 |
Correct |
8 ms |
4608 KB |
Output is correct |
3 |
Correct |
32 ms |
4608 KB |
Output is correct |
4 |
Correct |
96 ms |
4608 KB |
Output is correct |
5 |
Correct |
92 ms |
4608 KB |
Output is correct |
6 |
Correct |
80 ms |
4608 KB |
Output is correct |
7 |
Correct |
92 ms |
4608 KB |
Output is correct |
8 |
Correct |
76 ms |
4608 KB |
Output is correct |
9 |
Correct |
4 ms |
4608 KB |
Output is correct |
10 |
Correct |
4 ms |
4608 KB |
Output is correct |
11 |
Correct |
84 ms |
4608 KB |
Output is correct |
12 |
Correct |
88 ms |
4608 KB |
Output is correct |