Submission #72123

# Submission time Handle Problem Language Result Execution time Memory
72123 2018-08-26T05:24:16 Z (#2175, xdoju, kazel, pps789) Hill Reconstruction (FXCUP3_hill) C++17
100 / 100
1045 ms 22960 KB
#include <cstdio>
#include <set>
using namespace std;

int x[300002], y[300002];
int pv[300002];

struct S {
  int i, j, dx, dy;

  bool operator< (const S &r) const { // 가장 가파른 게 가장 앞에 오도록
    long long v = 1LL * r.dx * dy;
    long long w = 1LL * r.dy * dx;

    if(v != w) return v > w;

    return i < r.i;
  }
};

set<S> p;

long long area(int a, int b, int c){
  int x1 = x[a], y1 = y[a];
  int x2 = x[b], y2 = y[b];
  int x3 = x[c], y3 = y[c];

  long long v = 1LL * x1 * y2 + 1LL * x2 * y3 + 1LL * x3 * y1;
  long long w = 1LL * y1 * x2 + 1LL * y2 * x3 + 1LL * y3 * x1;

  return v > w ? v - w : w - v;
}

int gcd(int x, int y){
  if(x == 0 || y == 0) return x + y;

  for(;;){
    int t = x % y; if(t == 0) break;
    x = y; y = t;
  }

  return y;
}

int main(){
  int N; long long C; scanf("%d%lld", &N, &C);
  C *= 2;

  for(int i = 1; i <= N; i++) scanf("%d", &x[i]);
  for(int i = 1; i <= N; i++) scanf("%d", &y[i]);

  for(int i = 1; i < N; i++){
    p.insert({ i, i + 1, x[i + 1] - x[i], y[i + 1] - y[i] });
    pv[i + 1] = i;
  }

  for(;;){
    S now = *p.begin();
    if(now.i == 1) break; // convex

    int pre = pv[now.i]; // (pre, i)

    // pre, now.i, now.j triangle
    long long s = area(pre, now.i, now.j);

    if(s > C) break;

    C -= s;

    p.erase(p.begin());
    p.erase({ pre, now.i, x[now.i] - x[pre], y[now.i] - y[pre] });

    // printf("%d - %d, %d - %d\n", pre, now.i, now.i, now.j);

    p.insert({ pre, now.j, x[now.j] - x[pre], y[now.j] - y[pre] });

    // printf("%d - %d, %d / %d\n", pre, now.j, y[now.j] - y[pre], x[now.j] - x[pre]);

    pv[now.j] = pre;
  }

  S ans = *p.begin();
  int g = gcd(ans.dx, ans.dy);

  printf("%d/%d\n", ans.dy / g, ans.dx / g);
  return 0;
}

Compilation message

hill.cpp: In function 'int main()':
hill.cpp:46:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int N; long long C; scanf("%d%lld", &N, &C);
                       ~~~~~^~~~~~~~~~~~~~~~~~
hill.cpp:49:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for(int i = 1; i <= N; i++) scanf("%d", &x[i]);
                               ~~~~~^~~~~~~~~~~~~
hill.cpp:50:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for(int i = 1; i <= N; i++) scanf("%d", &y[i]);
                               ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 396 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 3 ms 492 KB Output is correct
6 Correct 3 ms 492 KB Output is correct
7 Correct 2 ms 520 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 396 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 3 ms 492 KB Output is correct
6 Correct 3 ms 492 KB Output is correct
7 Correct 2 ms 520 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 424 ms 22692 KB Output is correct
10 Correct 473 ms 22692 KB Output is correct
11 Correct 1045 ms 22840 KB Output is correct
12 Correct 603 ms 22916 KB Output is correct
13 Correct 270 ms 22916 KB Output is correct
14 Correct 215 ms 22916 KB Output is correct
15 Correct 219 ms 22916 KB Output is correct
16 Correct 216 ms 22916 KB Output is correct
17 Correct 194 ms 22916 KB Output is correct
18 Correct 168 ms 22916 KB Output is correct
19 Correct 229 ms 22960 KB Output is correct