답안 #1024703

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1024703 2024-07-16T09:26:28 Z TraianDanciu Long Distance Coach (JOI17_coach) C++17
16 / 100
1 ms 4444 KB
#include <stdio.h>
#include <algorithm>

#define MAXN 200000
#define INFINIT 2000000000000000000

static inline long long min(long long a, long long b) {
  return a < b ? a : b;
}
static inline long long max(long long a, long long b) {
  return a > b ? a : b;
}

// lichao incoming
struct Line {
  int a;
  long long b;
  
  inline long long eval(long long x) {
    return a * x + b;
  }
};

struct Node {
  Node *st, *dr;
  Line val;
  
  Node(Line val) {
    st = dr = nullptr;
    this->val = val;
  }
} *lichao = nullptr;

void update(Node *&node, long long left, long long right, Line val) {
  long long middle;
  
  if(node == nullptr) {
    node = new Node(val);
  } else {
    middle = (left + right) / 2;
    
    if(node->val.eval(middle) > val.eval(middle)) {
      std::swap(node->val, val);
    }
    
    if(node->val.eval(left) > val.eval(left)) {
      update(node->st, left, middle, val);
    }
    if(node->val.eval(right) > val.eval(right)) {
      update(node->dr, middle + 1, right, val);
    }
  }
}

long long query(Node *&node, long long left, long long right,
                                              long long pos) {
  long long middle, ans;
  
  if(node == nullptr) {
    return INFINIT;
  }
  
  middle = (left + right) / 2;
  ans = node->val.eval(pos);
  
  if(pos <= middle) {
    ans = min(ans, query(node->st, left, middle, pos));
  } else {
    ans = min(ans, query(node->dr, middle + 1, right, pos));
  }
  
  return ans;
}

struct Arbore {
  long long val, aux;
  int tip;
} v[2 * MAXN + 2];
static inline int compar(Arbore a, Arbore b) {
  return a.val < b.val;
}
long long sp[2 * MAXN + 2], dp[2 * MAXN];
int cnt[2 * MAXN + 2];

int main() {
  int n, m, w, i;
  long long x, t, mult;
  
  scanf("%lld%d%d%d%lld", &x, &n, &m, &w, &t);
  for(i = 1; i <= n; i++) {
    scanf("%lld", &v[i].aux);
    v[i].val = v[i].aux % t;
    v[i].tip = 0;
  }
  
  for(i = n + 1; i <= n + m; i++) {
    scanf("%lld%lld", &v[i].val, &v[i].aux);
    v[i].tip = 1;
  }
  
  m++;
  v[n + m] = (struct Arbore){.val = x % t, .aux = x, .tip = 0};
  std::sort(v + 1, v + n + m + 1, compar);
  
  for(i = 1; i <= n + m; i++) {
    sp[i] = sp[i - 1] + v[i].aux * v[i].tip;
    cnt[i] = cnt[i - 1] + v[i].tip;
  }
  
  dp[0] = 1LL * (x / t + 1) * w;
  for(i = 1; i <= n + m; i++) {
    update(lichao, 0, INFINIT, (struct Line){.a = -cnt[i - 1],
                                    .b = dp[i - 1] - sp[i - 1]});
    
    if(v[i].tip == 0) {
      mult = 1LL * (v[i].aux - v[i].val) / t * w;
      dp[i] = sp[i] + mult * cnt[i] + query(lichao, 0, INFINIT, mult);
    } else {
      dp[i] = dp[i - 1] + 1LL * w * (x / t + (v[i].val <= x % t));
    }
  }
  
  printf("%lld\n", dp[n + m]);
  return 0;
}

Compilation message

coach.cpp: In function 'int main()':
coach.cpp:89:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |   scanf("%lld%d%d%d%lld", &x, &n, &m, &w, &t);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
coach.cpp:91:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |     scanf("%lld", &v[i].aux);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
coach.cpp:97:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   97 |     scanf("%lld%lld", &v[i].val, &v[i].aux);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 0 ms 4444 KB Output is correct
14 Correct 0 ms 4444 KB Output is correct
15 Correct 0 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 0 ms 4444 KB Output is correct
21 Correct 0 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 0 ms 4444 KB Output is correct
14 Correct 0 ms 4444 KB Output is correct
15 Correct 0 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 0 ms 4444 KB Output is correct
21 Correct 0 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Incorrect 1 ms 4444 KB Output isn't correct
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 0 ms 4444 KB Output is correct
14 Correct 0 ms 4444 KB Output is correct
15 Correct 0 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 0 ms 4444 KB Output is correct
21 Correct 0 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Incorrect 1 ms 4444 KB Output isn't correct
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 0 ms 4444 KB Output is correct
14 Correct 0 ms 4444 KB Output is correct
15 Correct 0 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 0 ms 4444 KB Output is correct
21 Correct 0 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Incorrect 1 ms 4444 KB Output isn't correct
24 Halted 0 ms 0 KB -