Submission #284266

# Submission time Handle Problem Language Result Execution time Memory
284266 2020-08-27T06:13:38 Z 김동현(#5767) Aesthetic (NOI20_aesthetic) C++17
51 / 100
1182 ms 66168 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);
  set<tuple<int, int, ll>> ss;
  for(int i = 0; i < m; i++){
    int x = f(ie[i].x), y = f(ie[i].y);
    if(x > y) swap(x, y);
    if(x == y || ss.count({x, y, len[i]})) continue;
    e[x].emplace_back(y, i);
    e[y].emplace_back(x, i);
    ss.insert({x, y, len[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(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[f(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 << 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);
      |                    ~^~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8576 KB Output is correct
2 Correct 5 ms 8576 KB Output is correct
3 Correct 5 ms 8576 KB Output is correct
4 Correct 5 ms 8576 KB Output is correct
5 Correct 5 ms 8576 KB Output is correct
6 Correct 5 ms 8576 KB Output is correct
7 Correct 5 ms 8704 KB Output is correct
8 Correct 5 ms 8608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8576 KB Output is correct
2 Correct 5 ms 8576 KB Output is correct
3 Correct 5 ms 8576 KB Output is correct
4 Correct 5 ms 8576 KB Output is correct
5 Correct 5 ms 8576 KB Output is correct
6 Correct 5 ms 8576 KB Output is correct
7 Correct 5 ms 8704 KB Output is correct
8 Correct 5 ms 8608 KB Output is correct
9 Correct 8 ms 8832 KB Output is correct
10 Correct 8 ms 8932 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 8832 KB Output is correct
14 Correct 7 ms 8832 KB Output is correct
15 Correct 7 ms 8832 KB Output is correct
16 Correct 7 ms 8832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1118 ms 61248 KB Output is correct
2 Correct 1139 ms 61688 KB Output is correct
3 Correct 1090 ms 61048 KB Output is correct
4 Correct 1086 ms 60932 KB Output is correct
5 Correct 1117 ms 61048 KB Output is correct
6 Correct 1151 ms 62284 KB Output is correct
7 Correct 1100 ms 61944 KB Output is correct
8 Correct 1154 ms 62432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1182 ms 62232 KB Output is correct
2 Correct 1118 ms 61432 KB Output is correct
3 Correct 1097 ms 61816 KB Output is correct
4 Correct 1128 ms 62368 KB Output is correct
5 Correct 1085 ms 61432 KB Output is correct
6 Correct 1095 ms 61656 KB Output is correct
7 Correct 1182 ms 61328 KB Output is correct
8 Correct 1158 ms 61688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1049 ms 55820 KB Output is correct
2 Correct 399 ms 57592 KB Output is correct
3 Correct 630 ms 50936 KB Output is correct
4 Correct 660 ms 51320 KB Output is correct
5 Correct 625 ms 51324 KB Output is correct
6 Correct 617 ms 51448 KB Output is correct
7 Correct 655 ms 51192 KB Output is correct
8 Correct 655 ms 51664 KB Output is correct
9 Correct 621 ms 51320 KB Output is correct
10 Correct 621 ms 51704 KB Output is correct
11 Correct 613 ms 51448 KB Output is correct
12 Correct 1042 ms 56360 KB Output is correct
13 Correct 630 ms 51528 KB Output is correct
14 Correct 340 ms 66040 KB Output is correct
15 Correct 336 ms 66168 KB Output is correct
16 Correct 1071 ms 56264 KB Output is correct
17 Correct 1035 ms 54924 KB Output is correct
18 Correct 1025 ms 55668 KB Output is correct
19 Correct 389 ms 57980 KB Output is correct
20 Correct 389 ms 57976 KB Output is correct
21 Correct 390 ms 58104 KB Output is correct
22 Correct 389 ms 57976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1049 ms 55820 KB Output is correct
2 Correct 399 ms 57592 KB Output is correct
3 Correct 630 ms 50936 KB Output is correct
4 Correct 660 ms 51320 KB Output is correct
5 Correct 625 ms 51324 KB Output is correct
6 Correct 617 ms 51448 KB Output is correct
7 Correct 655 ms 51192 KB Output is correct
8 Correct 655 ms 51664 KB Output is correct
9 Correct 621 ms 51320 KB Output is correct
10 Correct 621 ms 51704 KB Output is correct
11 Correct 613 ms 51448 KB Output is correct
12 Correct 1042 ms 56360 KB Output is correct
13 Correct 630 ms 51528 KB Output is correct
14 Correct 340 ms 66040 KB Output is correct
15 Correct 336 ms 66168 KB Output is correct
16 Correct 1071 ms 56264 KB Output is correct
17 Correct 1035 ms 54924 KB Output is correct
18 Correct 1025 ms 55668 KB Output is correct
19 Correct 389 ms 57980 KB Output is correct
20 Correct 389 ms 57976 KB Output is correct
21 Correct 390 ms 58104 KB Output is correct
22 Correct 389 ms 57976 KB Output is correct
23 Correct 1008 ms 53732 KB Output is correct
24 Correct 394 ms 55672 KB Output is correct
25 Correct 629 ms 51064 KB Output is correct
26 Correct 661 ms 51128 KB Output is correct
27 Correct 649 ms 51192 KB Output is correct
28 Correct 648 ms 51448 KB Output is correct
29 Correct 693 ms 51356 KB Output is correct
30 Correct 616 ms 51320 KB Output is correct
31 Correct 625 ms 51704 KB Output is correct
32 Correct 601 ms 51196 KB Output is correct
33 Correct 627 ms 51728 KB Output is correct
34 Correct 965 ms 53116 KB Output is correct
35 Correct 634 ms 51832 KB Output is correct
36 Incorrect 108 ms 24184 KB Output isn't correct
37 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8576 KB Output is correct
2 Correct 5 ms 8576 KB Output is correct
3 Correct 5 ms 8576 KB Output is correct
4 Correct 5 ms 8576 KB Output is correct
5 Correct 5 ms 8576 KB Output is correct
6 Correct 5 ms 8576 KB Output is correct
7 Correct 5 ms 8704 KB Output is correct
8 Correct 5 ms 8608 KB Output is correct
9 Correct 8 ms 8832 KB Output is correct
10 Correct 8 ms 8932 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 8832 KB Output is correct
14 Correct 7 ms 8832 KB Output is correct
15 Correct 7 ms 8832 KB Output is correct
16 Correct 7 ms 8832 KB Output is correct
17 Correct 1118 ms 61248 KB Output is correct
18 Correct 1139 ms 61688 KB Output is correct
19 Correct 1090 ms 61048 KB Output is correct
20 Correct 1086 ms 60932 KB Output is correct
21 Correct 1117 ms 61048 KB Output is correct
22 Correct 1151 ms 62284 KB Output is correct
23 Correct 1100 ms 61944 KB Output is correct
24 Correct 1154 ms 62432 KB Output is correct
25 Correct 1182 ms 62232 KB Output is correct
26 Correct 1118 ms 61432 KB Output is correct
27 Correct 1097 ms 61816 KB Output is correct
28 Correct 1128 ms 62368 KB Output is correct
29 Correct 1085 ms 61432 KB Output is correct
30 Correct 1095 ms 61656 KB Output is correct
31 Correct 1182 ms 61328 KB Output is correct
32 Correct 1158 ms 61688 KB Output is correct
33 Correct 1049 ms 55820 KB Output is correct
34 Correct 399 ms 57592 KB Output is correct
35 Correct 630 ms 50936 KB Output is correct
36 Correct 660 ms 51320 KB Output is correct
37 Correct 625 ms 51324 KB Output is correct
38 Correct 617 ms 51448 KB Output is correct
39 Correct 655 ms 51192 KB Output is correct
40 Correct 655 ms 51664 KB Output is correct
41 Correct 621 ms 51320 KB Output is correct
42 Correct 621 ms 51704 KB Output is correct
43 Correct 613 ms 51448 KB Output is correct
44 Correct 1042 ms 56360 KB Output is correct
45 Correct 630 ms 51528 KB Output is correct
46 Correct 340 ms 66040 KB Output is correct
47 Correct 336 ms 66168 KB Output is correct
48 Correct 1071 ms 56264 KB Output is correct
49 Correct 1035 ms 54924 KB Output is correct
50 Correct 1025 ms 55668 KB Output is correct
51 Correct 389 ms 57980 KB Output is correct
52 Correct 389 ms 57976 KB Output is correct
53 Correct 390 ms 58104 KB Output is correct
54 Correct 389 ms 57976 KB Output is correct
55 Correct 1008 ms 53732 KB Output is correct
56 Correct 394 ms 55672 KB Output is correct
57 Correct 629 ms 51064 KB Output is correct
58 Correct 661 ms 51128 KB Output is correct
59 Correct 649 ms 51192 KB Output is correct
60 Correct 648 ms 51448 KB Output is correct
61 Correct 693 ms 51356 KB Output is correct
62 Correct 616 ms 51320 KB Output is correct
63 Correct 625 ms 51704 KB Output is correct
64 Correct 601 ms 51196 KB Output is correct
65 Correct 627 ms 51728 KB Output is correct
66 Correct 965 ms 53116 KB Output is correct
67 Correct 634 ms 51832 KB Output is correct
68 Incorrect 108 ms 24184 KB Output isn't correct
69 Halted 0 ms 0 KB -