답안 #258983

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
258983 2020-08-06T22:41:51 Z Bruteforceman 치료 계획 (JOI20_treatment) C++11
100 / 100
1024 ms 75088 KB
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const long long inf = 1e16;
long long d[maxn];
struct data {
  int t, l, r, c;
} a[maxn];
int n;
bool done[maxn];

bool isEdge(data p, data q) {
  if(p.t <= q.t) {
    return q.l + q.t <= p.r + p.t;
  } else {
    return q.l - q.t <= p.r - p.t;
  }
}

struct ds {
  vector <pair <int, int>> t[maxn * 4];
  ds () {}
  void add(int x, int y, int idx, int c, int b, int e) {
    t[c].push_back(make_pair(y, idx));
    if(b == e) {
      return ;
    }
    int m = (b + e) >> 1;
    int l = c << 1;
    int r = l + 1;
    if(x <= m) add(x, y, idx, l, b, m);
    else add(x, y, idx, r, m + 1, e);
  }
  void init(int c, int b, int e) {
    sort(t[c].begin(), t[c].end(), greater <pair <int, int>> ());
    if(b == e) return ;
    int m = (b + e) >> 1;
    int l = c << 1;
    int r = l + 1;
    init(l, b, m);
    init(r, m + 1, e);
  }
  void get(int x, int y, int val, vector <int> &v, int c, int b, int e) {
    if(x > y) return ;
    if(x <= b && e <= y) {
      while(!t[c].empty() && t[c].back().first <= val) {
        v.push_back(t[c].back().second);
        t[c].pop_back();
      }
      return ;
    }
    if(y < b || e < x) return ;
    int m = (b + e) >> 1;
    int l = c << 1;
    int r = l + 1;
    get(x, y, val, v, l, b, m);
    get(x, y, val, v, r, m + 1, e);
  }
} S, T;


int main() {
  int m;
  scanf("%d %d", &n, &m);
  map <int, int> cmp;
  for(int i = 1; i <= m; i++) {
    scanf("%d %d %d %d", &a[i].t, &a[i].l, &a[i].r, &a[i].c);
    a[i].l -= 1;
    cmp[a[i].t];
  }
  int idx = 0;
  for(auto &i : cmp) i.second = ++idx;
  priority_queue <pair <long long, int>, 
                  vector <pair <long long, int>>,
                  greater <pair <long long, int>>> Q;
  for(int i = 1; i <= m; i++) {
    if(a[i].l == 0) {
      d[i] = a[i].c;
      Q.emplace(d[i], i);
    } else {
      d[i] = inf;
    }
    S.add(cmp[a[i].t], a[i].l - a[i].t, i, 1, 1, idx);
    T.add(cmp[a[i].t], a[i].l + a[i].t, i, 1, 1, idx);
  }
  S.init(1, 1, idx);
  T.init(1, 1, idx);
  while(!Q.empty()) {
    int node = Q.top().second;
    long long dist = Q.top().first;
    Q.pop();
    if(done[node]) continue;
    done[node] = true;
    vector <int> v;
    S.get(1, cmp[a[node].t], a[node].r - a[node].t, v, 1, 1, idx);
    T.get(cmp[a[node].t], idx, a[node].r + a[node].t, v, 1, 1, idx);
    for(int i : v) {
      if(d[i] > d[node] + a[i].c) {
        d[i] = d[node] + a[i].c;
        Q.emplace(d[i], i);
      }
    }
  }
  long long ans = inf;
  for(int i = 1; i <= m; i++) {
    if(a[i].r == n) ans = min(ans, d[i]);
  }
  if(ans == inf) ans = -1;
  printf("%lld\n", ans);
  return 0;
}

Compilation message

treatment.cpp: In function 'int main()':
treatment.cpp:90:15: warning: unused variable 'dist' [-Wunused-variable]
     long long dist = Q.top().first;
               ^~~~
treatment.cpp:64:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &n, &m);
   ~~~~~^~~~~~~~~~~~~~~~~
treatment.cpp:67:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d %d", &a[i].t, &a[i].l, &a[i].r, &a[i].c);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 99 ms 24164 KB Output is correct
2 Correct 94 ms 23780 KB Output is correct
3 Correct 108 ms 24964 KB Output is correct
4 Correct 105 ms 24444 KB Output is correct
5 Correct 109 ms 25704 KB Output is correct
6 Correct 100 ms 23784 KB Output is correct
7 Correct 94 ms 23776 KB Output is correct
8 Correct 83 ms 23776 KB Output is correct
9 Correct 84 ms 23652 KB Output is correct
10 Correct 78 ms 23652 KB Output is correct
11 Correct 117 ms 26212 KB Output is correct
12 Correct 110 ms 26324 KB Output is correct
13 Correct 114 ms 25704 KB Output is correct
14 Correct 116 ms 25656 KB Output is correct
15 Correct 109 ms 23652 KB Output is correct
16 Correct 162 ms 23652 KB Output is correct
17 Correct 97 ms 23780 KB Output is correct
18 Correct 104 ms 26212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 19072 KB Output is correct
2 Correct 12 ms 19072 KB Output is correct
3 Correct 11 ms 19072 KB Output is correct
4 Correct 15 ms 19072 KB Output is correct
5 Correct 11 ms 19072 KB Output is correct
6 Correct 16 ms 19072 KB Output is correct
7 Correct 15 ms 19072 KB Output is correct
8 Correct 14 ms 19072 KB Output is correct
9 Correct 12 ms 19072 KB Output is correct
10 Correct 11 ms 19072 KB Output is correct
11 Correct 12 ms 19072 KB Output is correct
12 Correct 12 ms 19072 KB Output is correct
13 Correct 12 ms 19200 KB Output is correct
14 Correct 13 ms 19072 KB Output is correct
15 Correct 12 ms 19072 KB Output is correct
16 Correct 12 ms 19072 KB Output is correct
17 Correct 12 ms 19072 KB Output is correct
18 Correct 14 ms 19072 KB Output is correct
19 Correct 11 ms 19072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 19072 KB Output is correct
2 Correct 12 ms 19072 KB Output is correct
3 Correct 11 ms 19072 KB Output is correct
4 Correct 15 ms 19072 KB Output is correct
5 Correct 11 ms 19072 KB Output is correct
6 Correct 16 ms 19072 KB Output is correct
7 Correct 15 ms 19072 KB Output is correct
8 Correct 14 ms 19072 KB Output is correct
9 Correct 12 ms 19072 KB Output is correct
10 Correct 11 ms 19072 KB Output is correct
11 Correct 12 ms 19072 KB Output is correct
12 Correct 12 ms 19072 KB Output is correct
13 Correct 12 ms 19200 KB Output is correct
14 Correct 13 ms 19072 KB Output is correct
15 Correct 12 ms 19072 KB Output is correct
16 Correct 12 ms 19072 KB Output is correct
17 Correct 12 ms 19072 KB Output is correct
18 Correct 14 ms 19072 KB Output is correct
19 Correct 11 ms 19072 KB Output is correct
20 Correct 30 ms 21120 KB Output is correct
21 Correct 31 ms 21120 KB Output is correct
22 Correct 26 ms 20736 KB Output is correct
23 Correct 26 ms 20736 KB Output is correct
24 Correct 34 ms 21624 KB Output is correct
25 Correct 37 ms 21624 KB Output is correct
26 Correct 31 ms 21496 KB Output is correct
27 Correct 34 ms 21632 KB Output is correct
28 Correct 34 ms 21624 KB Output is correct
29 Correct 35 ms 21624 KB Output is correct
30 Correct 25 ms 21504 KB Output is correct
31 Correct 26 ms 21504 KB Output is correct
32 Correct 38 ms 21760 KB Output is correct
33 Correct 39 ms 21756 KB Output is correct
34 Correct 38 ms 21248 KB Output is correct
35 Correct 34 ms 21752 KB Output is correct
36 Correct 35 ms 21760 KB Output is correct
37 Correct 32 ms 21248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 99 ms 24164 KB Output is correct
2 Correct 94 ms 23780 KB Output is correct
3 Correct 108 ms 24964 KB Output is correct
4 Correct 105 ms 24444 KB Output is correct
5 Correct 109 ms 25704 KB Output is correct
6 Correct 100 ms 23784 KB Output is correct
7 Correct 94 ms 23776 KB Output is correct
8 Correct 83 ms 23776 KB Output is correct
9 Correct 84 ms 23652 KB Output is correct
10 Correct 78 ms 23652 KB Output is correct
11 Correct 117 ms 26212 KB Output is correct
12 Correct 110 ms 26324 KB Output is correct
13 Correct 114 ms 25704 KB Output is correct
14 Correct 116 ms 25656 KB Output is correct
15 Correct 109 ms 23652 KB Output is correct
16 Correct 162 ms 23652 KB Output is correct
17 Correct 97 ms 23780 KB Output is correct
18 Correct 104 ms 26212 KB Output is correct
19 Correct 12 ms 19072 KB Output is correct
20 Correct 12 ms 19072 KB Output is correct
21 Correct 11 ms 19072 KB Output is correct
22 Correct 15 ms 19072 KB Output is correct
23 Correct 11 ms 19072 KB Output is correct
24 Correct 16 ms 19072 KB Output is correct
25 Correct 15 ms 19072 KB Output is correct
26 Correct 14 ms 19072 KB Output is correct
27 Correct 12 ms 19072 KB Output is correct
28 Correct 11 ms 19072 KB Output is correct
29 Correct 12 ms 19072 KB Output is correct
30 Correct 12 ms 19072 KB Output is correct
31 Correct 12 ms 19200 KB Output is correct
32 Correct 13 ms 19072 KB Output is correct
33 Correct 12 ms 19072 KB Output is correct
34 Correct 12 ms 19072 KB Output is correct
35 Correct 12 ms 19072 KB Output is correct
36 Correct 14 ms 19072 KB Output is correct
37 Correct 11 ms 19072 KB Output is correct
38 Correct 30 ms 21120 KB Output is correct
39 Correct 31 ms 21120 KB Output is correct
40 Correct 26 ms 20736 KB Output is correct
41 Correct 26 ms 20736 KB Output is correct
42 Correct 34 ms 21624 KB Output is correct
43 Correct 37 ms 21624 KB Output is correct
44 Correct 31 ms 21496 KB Output is correct
45 Correct 34 ms 21632 KB Output is correct
46 Correct 34 ms 21624 KB Output is correct
47 Correct 35 ms 21624 KB Output is correct
48 Correct 25 ms 21504 KB Output is correct
49 Correct 26 ms 21504 KB Output is correct
50 Correct 38 ms 21760 KB Output is correct
51 Correct 39 ms 21756 KB Output is correct
52 Correct 38 ms 21248 KB Output is correct
53 Correct 34 ms 21752 KB Output is correct
54 Correct 35 ms 21760 KB Output is correct
55 Correct 32 ms 21248 KB Output is correct
56 Correct 700 ms 60620 KB Output is correct
57 Correct 690 ms 61008 KB Output is correct
58 Correct 652 ms 59476 KB Output is correct
59 Correct 692 ms 59748 KB Output is correct
60 Correct 486 ms 52692 KB Output is correct
61 Correct 647 ms 59544 KB Output is correct
62 Correct 699 ms 60456 KB Output is correct
63 Correct 965 ms 68432 KB Output is correct
64 Correct 815 ms 68648 KB Output is correct
65 Correct 132 ms 24912 KB Output is correct
66 Correct 452 ms 51560 KB Output is correct
67 Correct 693 ms 67832 KB Output is correct
68 Correct 606 ms 67796 KB Output is correct
69 Correct 543 ms 66128 KB Output is correct
70 Correct 809 ms 67700 KB Output is correct
71 Correct 644 ms 67784 KB Output is correct
72 Correct 556 ms 67412 KB Output is correct
73 Correct 879 ms 67744 KB Output is correct
74 Correct 397 ms 67280 KB Output is correct
75 Correct 366 ms 67388 KB Output is correct
76 Correct 830 ms 65092 KB Output is correct
77 Correct 984 ms 74248 KB Output is correct
78 Correct 873 ms 67288 KB Output is correct
79 Correct 976 ms 72012 KB Output is correct
80 Correct 911 ms 65876 KB Output is correct
81 Correct 667 ms 71636 KB Output is correct
82 Correct 907 ms 65620 KB Output is correct
83 Correct 1024 ms 71584 KB Output is correct
84 Correct 948 ms 71132 KB Output is correct
85 Correct 801 ms 71752 KB Output is correct
86 Correct 809 ms 71760 KB Output is correct
87 Correct 916 ms 71764 KB Output is correct
88 Correct 854 ms 72392 KB Output is correct
89 Correct 875 ms 71504 KB Output is correct
90 Correct 923 ms 74012 KB Output is correct
91 Correct 906 ms 73548 KB Output is correct
92 Correct 961 ms 71888 KB Output is correct
93 Correct 922 ms 71760 KB Output is correct
94 Correct 933 ms 72520 KB Output is correct
95 Correct 944 ms 71884 KB Output is correct
96 Correct 924 ms 74224 KB Output is correct
97 Correct 904 ms 74120 KB Output is correct
98 Correct 882 ms 73904 KB Output is correct
99 Correct 930 ms 73852 KB Output is correct
100 Correct 969 ms 74928 KB Output is correct
101 Correct 962 ms 73968 KB Output is correct
102 Correct 975 ms 75088 KB Output is correct
103 Correct 805 ms 72248 KB Output is correct