QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#574405#5540. City HallMay_27thWA 140ms16188kbC++202.9kb2024-09-18 21:59:182024-09-18 21:59:19

Judging History

你现在查看的是最新测评结果

  • [2024-09-18 21:59:19]
  • 评测
  • 测评结果:WA
  • 用时:140ms
  • 内存:16188kb
  • [2024-09-18 21:59:18]
  • 提交

answer

// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#include<bits/stdc++.h>
 
using namespace std;
 
#define i64 long long
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
struct Line {
  mutable i64 k, m, p;
  bool operator<(const Line& o) const { return k < o.k; }
  bool operator<(i64 x) const { return p < x; }
};
struct LineContainer : multiset<Line, less<>> {
  // (for doubles, use inf = 1/.0, div(a,b) = a/b)
  static const i64 inf = 1e18;
  i64 div(i64 a, i64 b) { // floored division
    return a / b - ((a ^ b) < 0 && a % b); }
  bool isect(iterator x, iterator y) {
    if (y == end()) return x->p = inf, 0;
    if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
    else x->p = div(y->m - x->m, x->k - y->k);
    return x->p >= y->p;
  }
  void add(i64 k, i64 m) {
    auto z = insert({k, m, 0}), y = z++, x = y;
    while (isect(y, z)) z = erase(z);
    if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
    while ((y = x) != begin() && (--x)->p >= y->p)
      isect(x, erase(y));
  }
  i64 query(i64 x) {
    // assert(!empty());
    if (empty()) return -inf;
    auto l = *lower_bound(x);
    return l.k * x + l.m;
  }
};

const int MAXN = 1e5 + 10;
const i64 INF = 1e18;
int N, M, S, T;
i64 H[MAXN], f[3][MAXN];
vector<int> G[MAXN];
void dijkstra(int st, int t) {
  for (int i = 1; i <= N; i ++) f[t][i] = INF;
  f[t][st] = 0;
  priority_queue<pair<i64, int>> pq; pq.push(mp(0, st));
  while (!pq.empty()) {
    auto [d, u] = pq.top(); pq.pop();
    if (f[t][u] != -d) continue;
    for (auto v : G[u]) {
      i64 add = (H[u] - H[v]) * (H[u] - H[v]);
      if (f[t][v] > f[t][u] + add) {
        f[t][v] = f[t][u] + add;
        pq.push(mp(-f[t][v], v));
      }
    }
  }
  // for (int i = 1; i <= N; i ++) {
  //   cout << t << " " << f[t][i] << "\n";
  // }
}
void Solve(void) {
  cin >> N >> M >> S >> T;
  for (int i = 1; i <= N; i ++) cin >> H[i];
  for (int i = 1; i <= M; i ++) {
    int u, v; cin >> u >> v;
    G[u].pb(v);
    G[v].pb(u);
  } dijkstra(S, 0); dijkstra(T, 1);
  long double ans = INF;
  for (int u = 1; u <= N; u ++) {
    ans = min(ans, (long double)(f[0][u] + f[1][u]));
    LineContainer convex;
    for (auto v : G[u]) {
      if (u == S && v == T) {
        ans = 0;
      }
      convex.add(2 * H[v], -(2 * f[0][v] + H[v] * H[v]));
    }
    for (auto v : G[u]) {
      long double cur = convex.query(H[v]);
      // cout << u << " " << v << " " << cur << " " << 2 * f[1][v] << "\n";
      cur = (cur - 2 * f[1][v] - H[v] * H[v])/2;
      ans = min(ans, -cur);
      // cout << u << " " << v << " " << cur << " " << f[1][v] << "\n";
    }
  }
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout << fixed << setprecision(10);
  int Tests = 1; // cin >> Tests; 
  while (Tests --) {
    Solve();    
  }
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 7932kb

input:

5 6 1 3
5 100 8 2 10
1 2
2 3
2 5
1 4
4 5
3 5

output:

4.5000000000

result:

ok found '4.5000000', expected '4.5000000', error '0.0000000'

Test #2:

score: 0
Accepted
time: 0ms
memory: 5900kb

input:

5 5 1 5
1 2 10 10 4
1 2
2 3
2 4
3 5
4 5

output:

3.0000000000

result:

ok found '3.0000000', expected '3.0000000', error '0.0000000'

Test #3:

score: 0
Accepted
time: 1ms
memory: 5900kb

input:

5 4 1 4
8 8 8 8 100
1 2
2 3
3 4
4 5

output:

0.0000000000

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #4:

score: 0
Accepted
time: 1ms
memory: 7888kb

input:

2 1 1 2
0 100000
1 2

output:

0.0000000000

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #5:

score: 0
Accepted
time: 106ms
memory: 15868kb

input:

632 199396 167 549
22513 93521 41403 35441 97617 53210 62622 4751 81863 14470 2994 93092 40432 30872 34423 36577 92540 92961 4110 14691 83321 10680 89112 80890 31108 24492 8973 42636 33792 27400 82361 85003 68940 31221 48625 276 52755 6649 34381 54399 6063 22628 17715 54052 58175 86609 82622 29917 9...

output:

0.0000000000

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #6:

score: 0
Accepted
time: 90ms
memory: 13436kb

input:

600 179700 396 574
83219 94660 9266 1939 32637 7117 33396 76947 42614 41001 87026 60210 25868 36044 35276 6147 36198 25195 50981 68230 32619 62563 28509 46643 43304 36195 99724 30903 77230 57923 36939 81397 17374 90947 48623 38120 48914 96481 98146 31707 9427 58735 82986 31328 94507 69081 51908 4188...

output:

0.0000000000

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #7:

score: 0
Accepted
time: 136ms
memory: 14184kb

input:

100000 200000 66364 98254
48399 8344 35365 18555 95271 13113 75220 25062 73969 71647 58212 68205 36310 45496 6965 59960 71592 81323 44341 95796 61521 63298 77830 16145 73103 83477 85246 53680 67289 68475 64978 43576 18969 28023 22848 55164 31276 12825 70999 49142 77203 40134 88148 59337 2357 70519 8...

output:

1019365473.0000000000

result:

ok found '1019365473.0000000', expected '1019365473.0000000', error '0.0000000'

Test #8:

score: 0
Accepted
time: 140ms
memory: 16116kb

input:

100000 200000 21412 38673
24050 75090 3692 20770 26840 57646 61096 3013 66291 73437 83126 67768 92979 69169 9389 70447 17151 74737 33407 3128 78504 52736 45853 27090 64395 24808 83577 24168 38576 37445 71022 40066 34908 90579 58370 31436 69812 39811 83370 50254 6518 72740 79316 67247 22759 65630 564...

output:

0.0000000000

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #9:

score: 0
Accepted
time: 125ms
memory: 16188kb

input:

100000 200000 75283 45047
38593 5224 81049 28255 11324 43744 51172 60916 67783 62336 96782 50029 48743 18780 32756 4774 32484 95733 17336 38046 98145 49655 68352 58308 21594 64540 11719 57827 30130 70076 95133 29886 93864 22677 28498 60413 44567 78935 64952 88954 85786 34019 75159 69192 15108 54645 ...

output:

6010044.5000000000

result:

ok found '6010044.5000000', expected '6010044.5000000', error '0.0000000'

Test #10:

score: 0
Accepted
time: 127ms
memory: 14084kb

input:

100000 200000 50293 63302
78731 76313 68601 46867 82806 57914 88495 43602 96202 44956 6593 96560 38650 61918 69911 48730 38668 8874 44449 25084 68496 18095 74789 52252 36631 68127 37908 63134 61923 68030 83186 81174 68083 78584 33622 74426 34099 32484 80162 10371 55894 65989 6374 76587 87442 50870 3...

output:

1926329544.0000000000

result:

ok found '1926329544.0000000', expected '1926329544.0000000', error '0.0000000'

Test #11:

score: 0
Accepted
time: 135ms
memory: 16156kb

input:

100000 200000 81105 2350
9856 14867 98102 45742 76449 20173 90566 85519 8273 40573 98784 21094 38040 75579 21248 37555 32846 95358 92476 76093 99209 81806 76912 80248 93022 87883 85938 20897 20561 19811 59752 42986 36831 82149 73443 66562 96573 52522 68268 28832 46601 39663 61155 69950 13823 36697 9...

output:

1746699958.0000000000

result:

ok found '1746699958.0000000', expected '1746699958.0000000', error '0.0000000'

Test #12:

score: -100
Wrong Answer
time: 64ms
memory: 12808kb

input:

100000 99999 27499 37224
50619 546 34928 55892 95127 83241 56167 1411 64361 65091 69529 50805 18412 47138 24827 35822 53959 16642 73725 69209 23403 82125 61003 92477 62663 85774 63819 6812 16133 1840 57576 82545 80082 56754 8563 84660 57303 4822 32294 74865 59555 75395 7723 97981 7648 7614 39995 373...

output:

2707856392.0000000000

result:

wrong answer 1st numbers differ - expected: '1479019958.0000000', found: '2707856392.0000000', error = '0.8308451'