답안 #284275

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
284275 2020-08-27T06:39:43 Z 김동현(#5767) Aesthetic (NOI20_aesthetic) C++17
100 / 100
819 ms 63596 KB
#include <bits/stdc++.h>
using namespace std;

using ll = __int128_t;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;

using vint = vector<int>;
using vll = vector<ll>;
using vld = vector<ld>;
using vpii = vector<pii>;
using vpil = vector<pil>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define x first
#define y second
#define all(v) v.begin(),v.end()

const ll INF = ll(1e30);

namespace Seg {
  const int sz = 524288;
  vll d(2 * sz, INF);
  
  void u(int s, int e, ll v) {
    for(s += sz, e += sz; s <= e; s /= 2, e /= 2) {
      if(s & 1) d[s++] = min(d[s], v);
      if(~e & 1) d[e--] = min(d[e], v);
    }
  }

  ll g(int x) {
    ll r = INF;
    for(x += sz; x; x /= 2) r = min(r, d[x]);
    return r;
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, m;
  cin >> n >> m;

  vll len(m), ext(m);
  vector<vpii> e(n + 1);
  for(int i = 0; i < m; i++){
    int x, y, z;
    cin >> x >> y >> z;
    len[i] = ll(z) << 20;
    if(len[i] == 0) len[i] = 1;
    e[x].emplace_back(y, i);
    e[y].emplace_back(x, i);
  }
  for(int i = m - 2; i >= 0; i--) ext[i] = max(ext[i + 1], len[i + 1]);

  vll ds(n + 1), de(n + 1);
  auto fnd = [&](int st, vll &d) {
    priority_queue<pli, vector<pli>, greater<pli>> pq;
    fill(all(d), INF);
    d[st] = 0;
    pq.emplace(0LL, st);
    while(!pq.empty()) {
      pli c = pq.top();
      pq.pop();
      if(c.x != d[c.y]) continue;
      for(pii &p : e[c.y]) {
        if(d[p.x] > c.x + len[p.y]) {
          d[p.x] = c.x + len[p.y];
          pq.emplace(d[p.x], p.x);
        }
      }
    }
  };
  fnd(1, ds);
  fnd(n, de);

  vint path(n + 1);
  for(int x = 1, c = 1; ; c++) {
    path[x] = c;
    if(x == n) break;
    for(pii &p : e[x]) {
      if(path[p.x]) continue;
      if(ds[p.x] == ds[x] + len[p.y] && de[p.x] + len[p.y] == de[x]) {
        x = p.x;
        Seg::u(c, c, ds[n] + ext[p.y]);
        break;
      }
    }
  }

  vint ms(n + 1), me(n + 1);
  function<int(int, int, vint&, const vll&)> g =
  [&](int x, int mode, vint &mem, const vll &d) {
    if(path[x]) return path[x];
    if(mem[x]) return mem[x];
    mem[x] = (mode == 0 ? n + 1 : -1);
    for(pii &p : e[x]) if(d[x] == d[p.x] + len[p.y]) {
      mem[x] = (
        mode == 0
        ? min(mem[x], g(p.x, mode, mem, d))
        : max(mem[x], g(p.x, mode, mem, d))
      );
    }
    return mem[x];
  };

  for(int i = 1; i <= n; i++) {
    for(pii &p : e[i]) {
      if(i > p.x) continue;
      if(path[i] && path[p.x]
        && abs(path[i] - path[p.x]) == 1
        && min(ds[i] + de[p.x], ds[p.x] + de[i]) + len[p.y] == ds[n]) continue;
      int A = g(i, 0, ms, ds), B = g(p.x, 1, me, de);
      Seg::u(A, B - 1, ds[i] + de[p.x] + len[p.y]);
      A = g(p.x, 0, ms, ds), B = g(i, 1, me, de);
      Seg::u(A, B - 1, ds[p.x] + de[i] + len[p.y]);
    }
  }

  ll ans = 0;
  for(int i = 1; ; i++) {
    ll t = Seg::g(i);
    if(t == INF) break;
    ans = max(ans, t);
  }
  cout << (long long)(ans >> 20) << '\n';

  return 0;
}

Compilation message

Aesthetic.cpp: In function 'void Seg::u(int, int, ll)':
Aesthetic.cpp:31:20: warning: operation on 's' may be undefined [-Wsequence-point]
   31 |       if(s & 1) d[s++] = min(d[s], v);
      |                   ~^~
Aesthetic.cpp:32:21: warning: operation on 'e' may be undefined [-Wsequence-point]
   32 |       if(~e & 1) d[e--] = min(d[e], v);
      |                    ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 16768 KB Output is correct
2 Correct 11 ms 16768 KB Output is correct
3 Correct 9 ms 16768 KB Output is correct
4 Correct 10 ms 16768 KB Output is correct
5 Correct 9 ms 16768 KB Output is correct
6 Correct 10 ms 16768 KB Output is correct
7 Correct 11 ms 16768 KB Output is correct
8 Correct 9 ms 16768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 16768 KB Output is correct
2 Correct 11 ms 16768 KB Output is correct
3 Correct 9 ms 16768 KB Output is correct
4 Correct 10 ms 16768 KB Output is correct
5 Correct 9 ms 16768 KB Output is correct
6 Correct 10 ms 16768 KB Output is correct
7 Correct 11 ms 16768 KB Output is correct
8 Correct 9 ms 16768 KB Output is correct
9 Correct 11 ms 17024 KB Output is correct
10 Correct 13 ms 17024 KB Output is correct
11 Correct 11 ms 17024 KB Output is correct
12 Correct 12 ms 17024 KB Output is correct
13 Correct 11 ms 17024 KB Output is correct
14 Correct 11 ms 17024 KB Output is correct
15 Correct 13 ms 17024 KB Output is correct
16 Correct 11 ms 17024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 773 ms 62888 KB Output is correct
2 Correct 765 ms 60108 KB Output is correct
3 Correct 749 ms 59768 KB Output is correct
4 Correct 779 ms 59552 KB Output is correct
5 Correct 748 ms 59768 KB Output is correct
6 Correct 788 ms 60664 KB Output is correct
7 Correct 786 ms 60536 KB Output is correct
8 Correct 757 ms 60792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 770 ms 63596 KB Output is correct
2 Correct 760 ms 60280 KB Output is correct
3 Correct 736 ms 60188 KB Output is correct
4 Correct 758 ms 60792 KB Output is correct
5 Correct 757 ms 59768 KB Output is correct
6 Correct 804 ms 60360 KB Output is correct
7 Correct 773 ms 60024 KB Output is correct
8 Correct 799 ms 60280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 731 ms 55532 KB Output is correct
2 Correct 270 ms 55544 KB Output is correct
3 Correct 391 ms 45072 KB Output is correct
4 Correct 376 ms 44872 KB Output is correct
5 Correct 391 ms 44920 KB Output is correct
6 Correct 361 ms 44792 KB Output is correct
7 Correct 365 ms 44792 KB Output is correct
8 Correct 362 ms 45052 KB Output is correct
9 Correct 385 ms 44968 KB Output is correct
10 Correct 374 ms 45176 KB Output is correct
11 Correct 368 ms 44920 KB Output is correct
12 Correct 716 ms 54540 KB Output is correct
13 Correct 371 ms 44920 KB Output is correct
14 Correct 214 ms 62968 KB Output is correct
15 Correct 216 ms 62968 KB Output is correct
16 Correct 733 ms 54532 KB Output is correct
17 Correct 707 ms 53632 KB Output is correct
18 Correct 723 ms 54124 KB Output is correct
19 Correct 270 ms 55672 KB Output is correct
20 Correct 274 ms 55672 KB Output is correct
21 Correct 281 ms 55736 KB Output is correct
22 Correct 270 ms 55672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 731 ms 55532 KB Output is correct
2 Correct 270 ms 55544 KB Output is correct
3 Correct 391 ms 45072 KB Output is correct
4 Correct 376 ms 44872 KB Output is correct
5 Correct 391 ms 44920 KB Output is correct
6 Correct 361 ms 44792 KB Output is correct
7 Correct 365 ms 44792 KB Output is correct
8 Correct 362 ms 45052 KB Output is correct
9 Correct 385 ms 44968 KB Output is correct
10 Correct 374 ms 45176 KB Output is correct
11 Correct 368 ms 44920 KB Output is correct
12 Correct 716 ms 54540 KB Output is correct
13 Correct 371 ms 44920 KB Output is correct
14 Correct 214 ms 62968 KB Output is correct
15 Correct 216 ms 62968 KB Output is correct
16 Correct 733 ms 54532 KB Output is correct
17 Correct 707 ms 53632 KB Output is correct
18 Correct 723 ms 54124 KB Output is correct
19 Correct 270 ms 55672 KB Output is correct
20 Correct 274 ms 55672 KB Output is correct
21 Correct 281 ms 55736 KB Output is correct
22 Correct 270 ms 55672 KB Output is correct
23 Correct 798 ms 57168 KB Output is correct
24 Correct 303 ms 55928 KB Output is correct
25 Correct 381 ms 44920 KB Output is correct
26 Correct 366 ms 44920 KB Output is correct
27 Correct 356 ms 44792 KB Output is correct
28 Correct 355 ms 45048 KB Output is correct
29 Correct 358 ms 44920 KB Output is correct
30 Correct 368 ms 44940 KB Output is correct
31 Correct 389 ms 45048 KB Output is correct
32 Correct 375 ms 44820 KB Output is correct
33 Correct 378 ms 44920 KB Output is correct
34 Correct 754 ms 56560 KB Output is correct
35 Correct 371 ms 44920 KB Output is correct
36 Correct 212 ms 54068 KB Output is correct
37 Correct 222 ms 55416 KB Output is correct
38 Correct 763 ms 55784 KB Output is correct
39 Correct 781 ms 57444 KB Output is correct
40 Correct 814 ms 58336 KB Output is correct
41 Correct 301 ms 57080 KB Output is correct
42 Correct 321 ms 57040 KB Output is correct
43 Correct 308 ms 56952 KB Output is correct
44 Correct 310 ms 57236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 16768 KB Output is correct
2 Correct 11 ms 16768 KB Output is correct
3 Correct 9 ms 16768 KB Output is correct
4 Correct 10 ms 16768 KB Output is correct
5 Correct 9 ms 16768 KB Output is correct
6 Correct 10 ms 16768 KB Output is correct
7 Correct 11 ms 16768 KB Output is correct
8 Correct 9 ms 16768 KB Output is correct
9 Correct 11 ms 17024 KB Output is correct
10 Correct 13 ms 17024 KB Output is correct
11 Correct 11 ms 17024 KB Output is correct
12 Correct 12 ms 17024 KB Output is correct
13 Correct 11 ms 17024 KB Output is correct
14 Correct 11 ms 17024 KB Output is correct
15 Correct 13 ms 17024 KB Output is correct
16 Correct 11 ms 17024 KB Output is correct
17 Correct 773 ms 62888 KB Output is correct
18 Correct 765 ms 60108 KB Output is correct
19 Correct 749 ms 59768 KB Output is correct
20 Correct 779 ms 59552 KB Output is correct
21 Correct 748 ms 59768 KB Output is correct
22 Correct 788 ms 60664 KB Output is correct
23 Correct 786 ms 60536 KB Output is correct
24 Correct 757 ms 60792 KB Output is correct
25 Correct 770 ms 63596 KB Output is correct
26 Correct 760 ms 60280 KB Output is correct
27 Correct 736 ms 60188 KB Output is correct
28 Correct 758 ms 60792 KB Output is correct
29 Correct 757 ms 59768 KB Output is correct
30 Correct 804 ms 60360 KB Output is correct
31 Correct 773 ms 60024 KB Output is correct
32 Correct 799 ms 60280 KB Output is correct
33 Correct 731 ms 55532 KB Output is correct
34 Correct 270 ms 55544 KB Output is correct
35 Correct 391 ms 45072 KB Output is correct
36 Correct 376 ms 44872 KB Output is correct
37 Correct 391 ms 44920 KB Output is correct
38 Correct 361 ms 44792 KB Output is correct
39 Correct 365 ms 44792 KB Output is correct
40 Correct 362 ms 45052 KB Output is correct
41 Correct 385 ms 44968 KB Output is correct
42 Correct 374 ms 45176 KB Output is correct
43 Correct 368 ms 44920 KB Output is correct
44 Correct 716 ms 54540 KB Output is correct
45 Correct 371 ms 44920 KB Output is correct
46 Correct 214 ms 62968 KB Output is correct
47 Correct 216 ms 62968 KB Output is correct
48 Correct 733 ms 54532 KB Output is correct
49 Correct 707 ms 53632 KB Output is correct
50 Correct 723 ms 54124 KB Output is correct
51 Correct 270 ms 55672 KB Output is correct
52 Correct 274 ms 55672 KB Output is correct
53 Correct 281 ms 55736 KB Output is correct
54 Correct 270 ms 55672 KB Output is correct
55 Correct 798 ms 57168 KB Output is correct
56 Correct 303 ms 55928 KB Output is correct
57 Correct 381 ms 44920 KB Output is correct
58 Correct 366 ms 44920 KB Output is correct
59 Correct 356 ms 44792 KB Output is correct
60 Correct 355 ms 45048 KB Output is correct
61 Correct 358 ms 44920 KB Output is correct
62 Correct 368 ms 44940 KB Output is correct
63 Correct 389 ms 45048 KB Output is correct
64 Correct 375 ms 44820 KB Output is correct
65 Correct 378 ms 44920 KB Output is correct
66 Correct 754 ms 56560 KB Output is correct
67 Correct 371 ms 44920 KB Output is correct
68 Correct 212 ms 54068 KB Output is correct
69 Correct 222 ms 55416 KB Output is correct
70 Correct 763 ms 55784 KB Output is correct
71 Correct 781 ms 57444 KB Output is correct
72 Correct 814 ms 58336 KB Output is correct
73 Correct 301 ms 57080 KB Output is correct
74 Correct 321 ms 57040 KB Output is correct
75 Correct 308 ms 56952 KB Output is correct
76 Correct 310 ms 57236 KB Output is correct
77 Correct 799 ms 61320 KB Output is correct
78 Correct 314 ms 59256 KB Output is correct
79 Correct 376 ms 48000 KB Output is correct
80 Correct 372 ms 47992 KB Output is correct
81 Correct 398 ms 48248 KB Output is correct
82 Correct 384 ms 47964 KB Output is correct
83 Correct 382 ms 48376 KB Output is correct
84 Correct 384 ms 48376 KB Output is correct
85 Correct 387 ms 47992 KB Output is correct
86 Correct 397 ms 48120 KB Output is correct
87 Correct 394 ms 48120 KB Output is correct
88 Correct 786 ms 58400 KB Output is correct
89 Correct 373 ms 48120 KB Output is correct
90 Correct 220 ms 55288 KB Output is correct
91 Correct 224 ms 55928 KB Output is correct
92 Correct 819 ms 60592 KB Output is correct
93 Correct 784 ms 60112 KB Output is correct
94 Correct 787 ms 59568 KB Output is correct
95 Correct 315 ms 59428 KB Output is correct
96 Correct 317 ms 59512 KB Output is correct
97 Correct 322 ms 59260 KB Output is correct
98 Correct 320 ms 59256 KB Output is correct