답안 #586550

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
586550 2022-06-30T11:36:41 Z MilosMilutinovic Autobahn (COI21_autobahn) C++14
100 / 100
241 ms 33856 KB
/**
 *    author:  wxhtzdy
 *    created: 30.06.2022 13:02:32
**/
#include <bits/stdc++.h>

using namespace std;

#define int long long

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);  
  int n, k, x;
  cin >> n >> k >> x;
  vector<int> l(n), t(n), r(n);
  for (int i = 0; i < n; i++) {
    cin >> l[i] >> t[i] >> r[i];
    t[i] = min(t[i], r[i] - l[i] + 1);
  }
  vector<int> xs;
  for (int i = 0; i < n; i++) {
    xs.push_back(l[i]);
    xs.push_back(l[i] + t[i]);
    xs.push_back(r[i] + 1);    
  }       
  int m = (int) xs.size();
  for (int i = 0; i < m; i++) {
    xs.push_back(xs[i] + x);
    xs.push_back(xs[i] - x);    
  }
  sort(xs.begin(), xs.end());
  xs.erase(unique(xs.begin(), xs.end()), xs.end());
  m = (int) xs.size();
  vector<int> sa(m);
  vector<int> sb(m);
  auto Get = [&](int x) {
    return lower_bound(xs.begin(), xs.end(), x) - xs.begin();
  };
  for (int i = 0; i < n; i++) {
    sa[Get(l[i])] += 1;  
    sa[Get(r[i] + 1)] -= 1;
    sb[Get(l[i] + t[i])] += 1;
    sb[Get(r[i] + 1)] -= 1;
  }
  for (int i = 1; i < m; i++) {
    sa[i] += sa[i - 1];
    sb[i] += sb[i - 1];
  }
  vector<long long> f(m);
  for (int i = 0; i < m - 1; i++) {
    long long d = xs[i + 1] - xs[i];
    f[i] = (i == 0 ? 0LL : f[i - 1]) + d * (sa[i] >= k ? sb[i] : 0);
  } 
  f[m - 1] = f[m - 2];
  long long ans = 0;
  for (int i = 0; i < m; i++) {
    int j = Get(xs[i] + x);
    j--;
    if (j >= i && j < m - 1 && (xs[j + 1] == xs[i] + x)) {
      ans = max(ans, f[j] - (i == 0 ? 0LL : f[i - 1]));
    }
  }
  cout << ans << '\n';
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 2 ms 456 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 2 ms 456 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 238 ms 33684 KB Output is correct
22 Correct 241 ms 33740 KB Output is correct
23 Correct 232 ms 33744 KB Output is correct
24 Correct 231 ms 33704 KB Output is correct
25 Correct 228 ms 33584 KB Output is correct
26 Correct 211 ms 33856 KB Output is correct
27 Correct 204 ms 33692 KB Output is correct
28 Correct 201 ms 33692 KB Output is correct
29 Correct 217 ms 33708 KB Output is correct