답안 #883163

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
883163 2023-12-04T16:57:40 Z MilosMilutinovic Long Distance Coach (JOI17_coach) C++14
71 / 100
2000 ms 17344 KB
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long x, t;
  int n, m, w;
  cin >> x >> n >> m >> w >> t;
  vector<long long> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  s.push_back(x);
  n += 1;
  m += 1;
  vector<long long> d(m);
  vector<int> c(m);
  for (int i = 1; i < m; i++) {
    cin >> d[i] >> c[i];
  }
  d[0] = 0;
  c[0] = 0;
  vector<int> order(m);
  iota(order.begin(), order.end(), 0);
  sort(order.begin(), order.end(), [&](int i, int j) {
    return d[i] < d[j];
  });
  {
    vector<long long> new_d(m);
    vector<int> new_c(m);
    for (int i = 0; i < m; i++) {
      new_d[i] = d[order[i]];
      new_c[i] = c[order[i]];
    }
    d = new_d;
    c = new_c;
  }
  const long long inf = (long long) 1e18;
  vector<long long> fir(m, inf);
  for (int i = 0; i < n; i++) {
    int low = 0, high = m - 1, idx = -1;
    while (low <= high) {
      int mid = low + high >> 1;
      if (d[mid] < (s[i] % t)) {
        idx = mid;
        low = mid + 1;
      } else {
        high = mid - 1;
      }
    }
    if (idx != -1) {
      fir[idx] = min(fir[idx], s[i] / t);
    }
  }
  vector<__int128> dp(m);
  dp[0] = (x / t + 1) * 1LL * w;
  for (int i = 1; i < m; i++) {
    dp[i] = dp[i - 1] + ((x - d[i]) / t + 1) * 1LL * w;
    if (fir[i] == inf) {
      continue;
    }
    __int128 sum_c = 0;
    for (int j = i; j > 0; j--) {
      sum_c += c[j];
      dp[i] = min(dp[i], dp[j - 1] + sum_c + (__int128) (fir[i]) * 1LL * (i - j + 1) * 1LL * w);
    }
  }
  cout << (long long) dp[m - 1] << '\n';
  return 0;
}

Compilation message

coach.cpp: In function 'int main()':
coach.cpp:45:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   45 |       int mid = low + high >> 1;
      |                 ~~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 452 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 452 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 452 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 3 ms 348 KB Output is correct
39 Correct 4 ms 348 KB Output is correct
40 Correct 4 ms 604 KB Output is correct
41 Correct 3 ms 600 KB Output is correct
42 Correct 3 ms 348 KB Output is correct
43 Correct 3 ms 348 KB Output is correct
44 Correct 3 ms 604 KB Output is correct
45 Correct 3 ms 348 KB Output is correct
46 Correct 5 ms 604 KB Output is correct
47 Correct 4 ms 604 KB Output is correct
48 Correct 3 ms 604 KB Output is correct
49 Correct 3 ms 348 KB Output is correct
50 Correct 3 ms 348 KB Output is correct
51 Correct 3 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 452 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 3 ms 348 KB Output is correct
39 Correct 4 ms 348 KB Output is correct
40 Correct 4 ms 604 KB Output is correct
41 Correct 3 ms 600 KB Output is correct
42 Correct 3 ms 348 KB Output is correct
43 Correct 3 ms 348 KB Output is correct
44 Correct 3 ms 604 KB Output is correct
45 Correct 3 ms 348 KB Output is correct
46 Correct 5 ms 604 KB Output is correct
47 Correct 4 ms 604 KB Output is correct
48 Correct 3 ms 604 KB Output is correct
49 Correct 3 ms 348 KB Output is correct
50 Correct 3 ms 348 KB Output is correct
51 Correct 3 ms 348 KB Output is correct
52 Execution timed out 2056 ms 17344 KB Time limit exceeded
53 Halted 0 ms 0 KB -