답안 #284264

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

using ll = long long;
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(1e18);

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;

  vpii ie(m);
  vll len(m), ext(m);
  vint p(n + 1);
  iota(all(p), 0);
  function<int(int)> f = [&](int x){ return p[x] = (x == p[x] ? x : f(p[x])); };
  for(int i = 0; i < m; i++) {
    cin >> ie[i].x >> ie[i].y >> len[i];
    if(len[i] == 0) p[f(ie[i].y)] = f(ie[i].x);
  }  
  for(int i = m - 2; i >= 0; i--) ext[i] = max(ext[i + 1], len[i + 1]);

  vector<vpii> e(n + 1);
  for(int i = 0; i < m; i++){
    int x = f(ie[i].x), y = f(ie[i].y);
    if(x == y) continue;
    e[x].emplace_back(y, i);
    e[y].emplace_back(x, i);
  }

  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(f(1), ds);
  fnd(f(n), de);

  vint path(n + 1);
  for(int x = f(1), c = 1; ; c++) {
    path[x] = c;
    if(x == f(n)) break;
    for(pii &p : e[x]) {
      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[f(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(path[i] && path[p.x] && abs(path[i] - path[p.x]) == 1) 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 << ans << '\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 5 ms 8576 KB Output is correct
2 Correct 5 ms 8576 KB Output is correct
3 Correct 6 ms 8576 KB Output is correct
4 Correct 6 ms 8576 KB Output is correct
5 Correct 5 ms 8576 KB Output is correct
6 Correct 6 ms 8576 KB Output is correct
7 Correct 5 ms 8576 KB Output is correct
8 Correct 6 ms 8576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8576 KB Output is correct
2 Correct 5 ms 8576 KB Output is correct
3 Correct 6 ms 8576 KB Output is correct
4 Correct 6 ms 8576 KB Output is correct
5 Correct 5 ms 8576 KB Output is correct
6 Correct 6 ms 8576 KB Output is correct
7 Correct 5 ms 8576 KB Output is correct
8 Correct 6 ms 8576 KB Output is correct
9 Correct 8 ms 8832 KB Output is correct
10 Correct 8 ms 8832 KB Output is correct
11 Correct 7 ms 8832 KB Output is correct
12 Correct 7 ms 8832 KB Output is correct
13 Correct 7 ms 8704 KB Output is correct
14 Correct 7 ms 8704 KB Output is correct
15 Correct 8 ms 8704 KB Output is correct
16 Correct 7 ms 8704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 792 ms 44408 KB Output is correct
2 Correct 778 ms 43768 KB Output is correct
3 Correct 778 ms 43256 KB Output is correct
4 Correct 795 ms 43368 KB Output is correct
5 Correct 755 ms 43512 KB Output is correct
6 Correct 819 ms 44536 KB Output is correct
7 Correct 798 ms 44408 KB Output is correct
8 Correct 791 ms 44792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 786 ms 45048 KB Output is correct
2 Correct 777 ms 43768 KB Output is correct
3 Correct 763 ms 44024 KB Output is correct
4 Correct 780 ms 44804 KB Output is correct
5 Correct 771 ms 44024 KB Output is correct
6 Correct 790 ms 44312 KB Output is correct
7 Correct 785 ms 44152 KB Output is correct
8 Correct 791 ms 44408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 732 ms 38644 KB Output is correct
2 Correct 254 ms 39928 KB Output is correct
3 Correct 349 ms 30968 KB Output is correct
4 Correct 350 ms 30840 KB Output is correct
5 Correct 338 ms 30972 KB Output is correct
6 Correct 345 ms 30972 KB Output is correct
7 Correct 338 ms 30840 KB Output is correct
8 Correct 330 ms 31096 KB Output is correct
9 Correct 328 ms 30960 KB Output is correct
10 Correct 365 ms 31020 KB Output is correct
11 Correct 369 ms 30968 KB Output is correct
12 Correct 753 ms 38156 KB Output is correct
13 Correct 369 ms 30968 KB Output is correct
14 Correct 223 ms 47992 KB Output is correct
15 Correct 230 ms 47992 KB Output is correct
16 Correct 713 ms 37836 KB Output is correct
17 Correct 704 ms 36988 KB Output is correct
18 Correct 700 ms 37548 KB Output is correct
19 Correct 253 ms 39800 KB Output is correct
20 Correct 260 ms 39868 KB Output is correct
21 Correct 254 ms 39800 KB Output is correct
22 Correct 262 ms 39932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 732 ms 38644 KB Output is correct
2 Correct 254 ms 39928 KB Output is correct
3 Correct 349 ms 30968 KB Output is correct
4 Correct 350 ms 30840 KB Output is correct
5 Correct 338 ms 30972 KB Output is correct
6 Correct 345 ms 30972 KB Output is correct
7 Correct 338 ms 30840 KB Output is correct
8 Correct 330 ms 31096 KB Output is correct
9 Correct 328 ms 30960 KB Output is correct
10 Correct 365 ms 31020 KB Output is correct
11 Correct 369 ms 30968 KB Output is correct
12 Correct 753 ms 38156 KB Output is correct
13 Correct 369 ms 30968 KB Output is correct
14 Correct 223 ms 47992 KB Output is correct
15 Correct 230 ms 47992 KB Output is correct
16 Correct 713 ms 37836 KB Output is correct
17 Correct 704 ms 36988 KB Output is correct
18 Correct 700 ms 37548 KB Output is correct
19 Correct 253 ms 39800 KB Output is correct
20 Correct 260 ms 39868 KB Output is correct
21 Correct 254 ms 39800 KB Output is correct
22 Correct 262 ms 39932 KB Output is correct
23 Correct 718 ms 37104 KB Output is correct
24 Correct 266 ms 39032 KB Output is correct
25 Correct 339 ms 30968 KB Output is correct
26 Correct 339 ms 30840 KB Output is correct
27 Correct 342 ms 30968 KB Output is correct
28 Correct 343 ms 30840 KB Output is correct
29 Correct 373 ms 31096 KB Output is correct
30 Correct 353 ms 30840 KB Output is correct
31 Correct 346 ms 31024 KB Output is correct
32 Correct 342 ms 30712 KB Output is correct
33 Correct 353 ms 30968 KB Output is correct
34 Correct 711 ms 36628 KB Output is correct
35 Correct 360 ms 30972 KB Output is correct
36 Incorrect 104 ms 24696 KB Output isn't correct
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8576 KB Output is correct
2 Correct 5 ms 8576 KB Output is correct
3 Correct 6 ms 8576 KB Output is correct
4 Correct 6 ms 8576 KB Output is correct
5 Correct 5 ms 8576 KB Output is correct
6 Correct 6 ms 8576 KB Output is correct
7 Correct 5 ms 8576 KB Output is correct
8 Correct 6 ms 8576 KB Output is correct
9 Correct 8 ms 8832 KB Output is correct
10 Correct 8 ms 8832 KB Output is correct
11 Correct 7 ms 8832 KB Output is correct
12 Correct 7 ms 8832 KB Output is correct
13 Correct 7 ms 8704 KB Output is correct
14 Correct 7 ms 8704 KB Output is correct
15 Correct 8 ms 8704 KB Output is correct
16 Correct 7 ms 8704 KB Output is correct
17 Correct 792 ms 44408 KB Output is correct
18 Correct 778 ms 43768 KB Output is correct
19 Correct 778 ms 43256 KB Output is correct
20 Correct 795 ms 43368 KB Output is correct
21 Correct 755 ms 43512 KB Output is correct
22 Correct 819 ms 44536 KB Output is correct
23 Correct 798 ms 44408 KB Output is correct
24 Correct 791 ms 44792 KB Output is correct
25 Correct 786 ms 45048 KB Output is correct
26 Correct 777 ms 43768 KB Output is correct
27 Correct 763 ms 44024 KB Output is correct
28 Correct 780 ms 44804 KB Output is correct
29 Correct 771 ms 44024 KB Output is correct
30 Correct 790 ms 44312 KB Output is correct
31 Correct 785 ms 44152 KB Output is correct
32 Correct 791 ms 44408 KB Output is correct
33 Correct 732 ms 38644 KB Output is correct
34 Correct 254 ms 39928 KB Output is correct
35 Correct 349 ms 30968 KB Output is correct
36 Correct 350 ms 30840 KB Output is correct
37 Correct 338 ms 30972 KB Output is correct
38 Correct 345 ms 30972 KB Output is correct
39 Correct 338 ms 30840 KB Output is correct
40 Correct 330 ms 31096 KB Output is correct
41 Correct 328 ms 30960 KB Output is correct
42 Correct 365 ms 31020 KB Output is correct
43 Correct 369 ms 30968 KB Output is correct
44 Correct 753 ms 38156 KB Output is correct
45 Correct 369 ms 30968 KB Output is correct
46 Correct 223 ms 47992 KB Output is correct
47 Correct 230 ms 47992 KB Output is correct
48 Correct 713 ms 37836 KB Output is correct
49 Correct 704 ms 36988 KB Output is correct
50 Correct 700 ms 37548 KB Output is correct
51 Correct 253 ms 39800 KB Output is correct
52 Correct 260 ms 39868 KB Output is correct
53 Correct 254 ms 39800 KB Output is correct
54 Correct 262 ms 39932 KB Output is correct
55 Correct 718 ms 37104 KB Output is correct
56 Correct 266 ms 39032 KB Output is correct
57 Correct 339 ms 30968 KB Output is correct
58 Correct 339 ms 30840 KB Output is correct
59 Correct 342 ms 30968 KB Output is correct
60 Correct 343 ms 30840 KB Output is correct
61 Correct 373 ms 31096 KB Output is correct
62 Correct 353 ms 30840 KB Output is correct
63 Correct 346 ms 31024 KB Output is correct
64 Correct 342 ms 30712 KB Output is correct
65 Correct 353 ms 30968 KB Output is correct
66 Correct 711 ms 36628 KB Output is correct
67 Correct 360 ms 30972 KB Output is correct
68 Incorrect 104 ms 24696 KB Output isn't correct
69 Halted 0 ms 0 KB -