답안 #7416

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
7416 2014-08-05T04:54:54 Z gs13068 막대기 (KOI13_game) C++
100 / 100
164 ms 8856 KB
#include<cstdio>
#include<algorithm>
#include<map>

std::map<int,long long> u,d;
std::pair<int,int> a[100000];

int main()
{
  long long r=0;
  long long uv,dv;
  int i,n,m;
  scanf("%d%d",&n,&m);
  for(i=0;i<n;i++)scanf("%d%d",&a[i].first,&a[i].second);
  std::sort(a,a+n);
  for(i=0;i<n;i++)
  {
    if(u.find(a[i].first)==u.end())uv=0;
    else uv=u[a[i].first];
    if(d.find(a[i].second)==d.end())dv=0;
    else dv=d[a[i].second];

    uv+=std::abs(a[i].first-a[i].second)+m;
    dv+=std::abs(a[i].first-a[i].second)+m;

    if(u.find(a[i].first)==u.end()||u[a[i].first]<dv)u[a[i].first]=dv;
    if(d.find(a[i].second)==d.end()||d[a[i].second]<uv)d[a[i].second]=uv;

    r=std::max(r,std::max(uv,dv));
  }
  printf("%lld",r);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1992 KB Output is correct
2 Correct 0 ms 1992 KB Output is correct
3 Correct 0 ms 1992 KB Output is correct
4 Correct 0 ms 1992 KB Output is correct
5 Correct 0 ms 1992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 1992 KB Output is correct
2 Correct 36 ms 1992 KB Output is correct
3 Correct 72 ms 1992 KB Output is correct
4 Correct 60 ms 1992 KB Output is correct
5 Correct 76 ms 1992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1992 KB Output is correct
2 Correct 0 ms 1992 KB Output is correct
3 Correct 0 ms 1992 KB Output is correct
4 Correct 0 ms 1992 KB Output is correct
5 Correct 0 ms 1992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1992 KB Output is correct
2 Correct 0 ms 1992 KB Output is correct
3 Correct 0 ms 1992 KB Output is correct
4 Correct 0 ms 1992 KB Output is correct
5 Correct 0 ms 1992 KB Output is correct
6 Correct 0 ms 1992 KB Output is correct
7 Correct 0 ms 1992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2256 KB Output is correct
2 Correct 8 ms 2388 KB Output is correct
3 Correct 52 ms 3708 KB Output is correct
4 Correct 116 ms 7140 KB Output is correct
5 Correct 116 ms 7800 KB Output is correct
6 Correct 124 ms 7404 KB Output is correct
7 Correct 144 ms 8856 KB Output is correct
8 Correct 164 ms 8196 KB Output is correct
9 Correct 8 ms 2520 KB Output is correct
10 Correct 8 ms 2124 KB Output is correct
11 Correct 104 ms 6084 KB Output is correct
12 Correct 100 ms 6084 KB Output is correct