Submission #72066

# Submission time Handle Problem Language Result Execution time Memory
72066 2018-08-26T05:06:55 Z (#2175, xdoju, kazel, pps789) Hill Reconstruction (FXCUP3_hill) C++17
32 / 100
351 ms 22232 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 { // 가장 가파른 게 가장 앞에 오도록
    return 1LL * r.dx * dy > 1LL * r.dy * dx;
  }
};

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] });

    p.insert({ pre, now.j, x[now.j] - x[pre], y[now.j] - y[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:41: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:44: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:45: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 392 KB Output is correct
4 Correct 5 ms 392 KB Output is correct
5 Correct 3 ms 440 KB Output is correct
6 Correct 3 ms 452 KB Output is correct
7 Correct 2 ms 452 KB Output is correct
8 Correct 3 ms 580 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 392 KB Output is correct
4 Correct 5 ms 392 KB Output is correct
5 Correct 3 ms 440 KB Output is correct
6 Correct 3 ms 452 KB Output is correct
7 Correct 2 ms 452 KB Output is correct
8 Correct 3 ms 580 KB Output is correct
9 Incorrect 351 ms 22232 KB Output isn't correct
10 Halted 0 ms 0 KB -