답안 #31206

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
31206 2017-08-13T16:04:11 Z leejseo 먼 별 (KOI16_dist) C++
100 / 100
303 ms 2924 KB
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <vector>
 
using namespace std;
 
typedef struct {
  int x, y, dx, dy;
} star;
 
#define MAX_T 10000000
#define MAX_N 30000
 
star L[MAX_N];
 
int n, T;
 
long long int dist(star &a, star &b, int t){
  long long int a_x = a.x + t*a.dx;
  long long int a_y = a.y + t*a.dy;
  long long int b_x = b.x + t*b.dx;
  long long int b_y = b.y + t*b.dy;
  return (a_x - b_x)*(a_x - b_x) + (a_y - b_y) * (a_y - b_y);
}
/* 
long long int g(int t){
  long long cnt = 0;
  for(int i=0; i<n; i++){
    for(int j=0; j<i; j++){
      long long temp = dist(L[i], L[j], t);
      if (temp > cnt){
        cnt = temp;
      }
    }
  }
  return cnt;
}
*/

struct compare_with_time
{ 
  compare_with_time(int t) { m_t = t; } // only if you really need the object state
  int m_t;

  bool operator()(const star &a, const star &b) const 
  { 
    if ((a.x + m_t * a.dx) < (b.x + m_t * b.dx)) return true;
    if (((a.x + m_t * a.dx) == (b.x + m_t * b.dx))&& ((a.y + m_t * a.dy) < (b.y + m_t * b.dy))) return true;
    return false;
  }
};
/*
star items[MAX_STAR];
int item_count;
int t;

sort(item, item + item_count, compare_with_time(t))

int compare(star a, star b){
  if (a.x > b.x) return 1;
  else if (a.x == b.x){
    if (a.y > b.y) return 1;
    if (a.y < b.y) return -1;
    return 0;
  }
  return -1;
}
*/

int CCW(const star &P, const star &P1, const star &P2, int t){
  long long x1 = P.x + P.dx * t;
  long long x2 = P1.x + P1.dx * t;
  long long x3 = P2.x + P2.dx * t;
  long long y1 = P.y + P.dy * t;
  long long y2 = P1.y + P1.dy * t;
  long long y3 = P2.y + P2.dy * t;
  long long Area = (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1);
  if (Area == 0) return 0;
  if (Area > 0) return 1;
  return -1;
}

long long dist(const star &a, const star &b, int t){
  long long delta_x = (a.x + t * a.dx) - (b.x + t*b.dx);
  long long delta_y = (a.y + t * a.dy) - (b.y + t*b.dy);
  return delta_x * delta_x + delta_y * delta_y;
}

bool temp_f(vector<star> &U, vector<star> &L , int i, int j, int t){
  long long a1, a2, a3, a4;
  a1 = (U[i+1].y + U[i+1].dy * t) - (U[i].y + U[i].dy * t);
  a2 = (L[j].x + L[j].dx * t) - (L[j-1].x + L[j-1].dx * t);
  a3 = (L[j].y + L[j].dy * t) - (L[j-1].y + L[j-1].dy * t);
  a4 = (U[i+1].x + U[i+1].dx * t) - (U[i].x + U[i].dx * t);
  return (a1 * a2) > (a3 * a4);
}

long long g(int t){
  sort(L, L+n, compare_with_time(t));
  vector<star> UP, LO;
  int u=0, l=0;
  for (int i=0; i<n; i++){
    star q = L[i];
    while ((u > 1) && (CCW(UP[u-2], UP[u-1], q, t) >= 0)){
      UP.pop_back();
      u = u-1;
    }
    while ((l > 1) && (CCW(LO[l-2], LO[l-1], q, t) <= 0)){
      LO.pop_back();
      l = l-1;
    }
    UP.push_back(q);
    u++;
    LO.push_back(q);
    l++;
  }
  int i = 0;
  int j = l-1;
  long long DIST = 0;
  while ((i < u-1) || (j > 0)){
    long long cnt = dist(UP[i], LO[j], t);
    if (cnt > DIST) DIST = cnt;
    if (i == u-1) j--;
    else if (j == 0) i++;
    else if (temp_f(UP, LO, i, j, t)) i++;
    else j--;
  }
  long long cnt = dist(UP[i], LO[j], t);
  if (cnt > DIST) DIST = cnt;
  return DIST;
}

int f(){
  int lo = 0;
  int hi = T;
  while (lo <= hi){
    int llh = (2*lo + hi)/3;
    int lhh = (lo + 2*hi + 1)/3;
    if (g(llh) <= g(lhh)) hi = lhh - 1;
    else lo = llh+1;
  }
  return lo;
}
 
int main(){
  scanf("%d%d", &n, &T);
  for (int i=0; i<n; i++){
    scanf("%d%d%d%d", &(L[i].x), &(L[i].y), &(L[i].dx), &(L[i].dy));
  }
  int day = f();
  long long d = g(day);
  printf("%d\n", day);
  printf("%lld\n", d);
  return 0;
}

Compilation message

dist.cpp: In function 'int main()':
dist.cpp:147:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &n, &T);
                        ^
dist.cpp:149:68: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d%d", &(L[i].x), &(L[i].y), &(L[i].dx), &(L[i].dy));
                                                                    ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1644 KB Output is correct
2 Correct 0 ms 1644 KB Output is correct
3 Correct 0 ms 1644 KB Output is correct
4 Correct 0 ms 1644 KB Output is correct
5 Correct 0 ms 1644 KB Output is correct
6 Correct 0 ms 1644 KB Output is correct
7 Correct 0 ms 1644 KB Output is correct
8 Correct 0 ms 1644 KB Output is correct
9 Correct 0 ms 1644 KB Output is correct
10 Correct 0 ms 1644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1644 KB Output is correct
2 Correct 0 ms 1644 KB Output is correct
3 Correct 0 ms 1644 KB Output is correct
4 Correct 0 ms 1644 KB Output is correct
5 Correct 0 ms 1644 KB Output is correct
6 Correct 0 ms 1644 KB Output is correct
7 Correct 0 ms 1644 KB Output is correct
8 Correct 0 ms 1644 KB Output is correct
9 Correct 0 ms 1644 KB Output is correct
10 Correct 0 ms 1644 KB Output is correct
11 Correct 6 ms 1644 KB Output is correct
12 Correct 6 ms 1644 KB Output is correct
13 Correct 3 ms 1644 KB Output is correct
14 Correct 9 ms 1644 KB Output is correct
15 Correct 3 ms 1644 KB Output is correct
16 Correct 3 ms 1644 KB Output is correct
17 Correct 3 ms 1644 KB Output is correct
18 Correct 6 ms 1644 KB Output is correct
19 Correct 3 ms 1644 KB Output is correct
20 Correct 6 ms 1644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 1644 KB Output is correct
2 Correct 53 ms 1644 KB Output is correct
3 Correct 46 ms 1644 KB Output is correct
4 Correct 39 ms 2572 KB Output is correct
5 Correct 36 ms 1644 KB Output is correct
6 Correct 59 ms 2572 KB Output is correct
7 Correct 43 ms 1644 KB Output is correct
8 Correct 46 ms 1644 KB Output is correct
9 Correct 53 ms 2924 KB Output is correct
10 Correct 46 ms 1644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1644 KB Output is correct
2 Correct 0 ms 1644 KB Output is correct
3 Correct 0 ms 1644 KB Output is correct
4 Correct 0 ms 1644 KB Output is correct
5 Correct 0 ms 1644 KB Output is correct
6 Correct 0 ms 1644 KB Output is correct
7 Correct 0 ms 1644 KB Output is correct
8 Correct 0 ms 1644 KB Output is correct
9 Correct 0 ms 1644 KB Output is correct
10 Correct 0 ms 1644 KB Output is correct
11 Correct 6 ms 1644 KB Output is correct
12 Correct 6 ms 1644 KB Output is correct
13 Correct 3 ms 1644 KB Output is correct
14 Correct 9 ms 1644 KB Output is correct
15 Correct 3 ms 1644 KB Output is correct
16 Correct 3 ms 1644 KB Output is correct
17 Correct 3 ms 1644 KB Output is correct
18 Correct 6 ms 1644 KB Output is correct
19 Correct 3 ms 1644 KB Output is correct
20 Correct 6 ms 1644 KB Output is correct
21 Correct 49 ms 1644 KB Output is correct
22 Correct 53 ms 1644 KB Output is correct
23 Correct 46 ms 1644 KB Output is correct
24 Correct 39 ms 2572 KB Output is correct
25 Correct 36 ms 1644 KB Output is correct
26 Correct 59 ms 2572 KB Output is correct
27 Correct 43 ms 1644 KB Output is correct
28 Correct 46 ms 1644 KB Output is correct
29 Correct 53 ms 2924 KB Output is correct
30 Correct 46 ms 1644 KB Output is correct
31 Correct 303 ms 1644 KB Output is correct
32 Correct 209 ms 1644 KB Output is correct
33 Correct 189 ms 1644 KB Output is correct
34 Correct 213 ms 1644 KB Output is correct
35 Correct 183 ms 1644 KB Output is correct
36 Correct 156 ms 2572 KB Output is correct
37 Correct 153 ms 1644 KB Output is correct
38 Correct 179 ms 1644 KB Output is correct
39 Correct 193 ms 1644 KB Output is correct
40 Correct 283 ms 1644 KB Output is correct
41 Correct 163 ms 2572 KB Output is correct
42 Correct 273 ms 2924 KB Output is correct