QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#154749#7118. Closing Timeyzy10 84ms65068kbC++173.2kb2023-08-31 21:49:402024-04-28 06:35:28

Judging History

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

  • [2024-04-28 06:35:28]
  • 管理员手动重测本题所有提交记录
  • 测评结果:0
  • 用时:84ms
  • 内存:65068kb
  • [2023-08-31 21:49:40]
  • 评测
  • 测评结果:0
  • 用时:73ms
  • 内存:59928kb
  • [2023-08-31 21:49:40]
  • 提交

answer

#include <bits/stdc++.h>

#include "closing.h"

#if defined(LOCAL)
#define DBG_MACRO_NO_WARNING
#include <dbg.hpp>

#include "grader.cpp"
#else
#define dbg(x...) (0)
#endif

using namespace std;

using ll = long long;

// #define int ll
#define rep(i, f, t) for (int i = (f), ed##i = (t); i <= ed##i; ++i)
#define re(i, t) rep (i, 1, t)
#define per(i, t, f) for (int i = (t), ed##i = (f); i >= ed##i; --i)
#define ste(i, f, t, s) for (int i = (f), ed##i = (t); i <= ed##i; i += s)
#define nxt(i, f, g) for (int i = g.h[f]; i; i = g.e[i].n)
#define umod(x) ((x) >= mo && ((x) -= mo))
#define dmod(x) ((x) < 0 && ((x) += mo))
#define y1 y1__
#define fio(x) (freopen(x ".in", "r", stdin), freopen(x ".out", "w", stdout))

template <class T, class E>
__attribute__((always_inline)) inline void up(T &x, E &&y) {
  if (x < y) x = y;
}
template <class T, class E>
__attribute__((always_inline)) inline void down(T &x, E &&y) {
  if (y < x) x = y;
}

const int N = 1e6 + 9;
const ll inf = 1e18 + 9;

struct E {
  int f, t, v;
} es[N];
int n, X, Y, a[N];
ll m, dis[N][3];
vector<pair<int, int>> e[N];
struct Node {
  ll v;
  int p, f;
};
inline bool operator<(Node x, Node y) { return x.v > y.v; }
priority_queue<Node> q[3];

inline void Dfs1(int f, int fa, int id) {
  for (auto [t, v] : e[f]) {
    if (t == fa) continue;
    dis[t][id] = dis[f][id] + v;
    Dfs1(t, f, id);
  }
}

inline void Push(int p, int x) {
  a[p] = x;
  rep (i, 0, 2) {
    if (i == x) continue;
    q[max(0, i - x)].push({dis[p][i] - dis[p][x], p, x});
  }
}

inline int Work() {
  rep (i, 0, 2) q[i] = {};
  re (i, n) e[i].clear();
  re (i, n - 1) {
    auto [f, t, v] = es[i];
    e[f].push_back({t, v});
    e[t].push_back({f, v});
  }
  dis[X][1] = dis[Y][2] = 0;
  Dfs1(X, 0, 1);
  Dfs1(Y, 0, 2);
  re (i, n)
    if (dis[i][1] > dis[i][2]) swap(dis[i][1], dis[i][2]);
  ll sum = 0, ans = 0;
  vector<ll> vec;
  re (i, n)
    if (dis[i][1] + dis[i][2] == dis[X][2]) {
      vec.push_back(dis[i][1]);
      sum += dis[i][1];
      Push(i, 1);
      ++ans;
    } else
      Push(i, 0);
  if (m < sum) {
    int res = 0;
    sort(vec.begin(), vec.end());
    // dbg(vec);
    for (auto x : vec)
      if (m >= x)
        m -= x, ++res;
      else
        return res;
  }
  m -= sum;
  // dbg(m, ans);
  while (1) {
    rep (i, 0, 2)
      for (auto tp = q[i].top(); a[tp.p] != tp.f; tp = q[i].top()) q[i].pop();
    if (ll c1 = q[1].empty() ? inf : q[1].top().v,
        c2 = (q[2].empty() ? inf : q[2].top().v) + (q[0].empty() ? inf : q[0].top().v);
        c1 < c2) {
      if (m < c1) break;
      m -= c1;
      ++ans;
      auto tp = q[1].top();
      q[1].pop();
      Push(tp.v, tp.f + 1);
    } else {
      if (m < c2) break;
      m -= c2;
      ++ans;
      auto tp = q[2].top();
      q[2].pop();
      Push(tp.p, tp.f + 2);
      tp = q[0].top();
      q[0].pop();
      Push(tp.p, tp.f - 1);
    }
  }
  return ans;
}

int max_score(int N, int X, int Y, long long K, std::vector<int> U, std::vector<int> V,
              std::vector<int> W) {
  ::n = N, ::X = X + 1, ::Y = Y + 1, ::m = K;
  rep (i, 0, n - 2) es[i + 1] = {U[i] + 1, V[i] + 1, W[i]};
  return Work();
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 84ms
memory: 65068kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
200000 31011 61157 8517583098
31011 129396 964383
1655 129396 331139
1655 191487 566483
110385 191487 865248
43212 110385 542661
43212 81682 13766
81682 91774 546589
91774 124706 780638
124706 175650 118706
10421 175650 615314
10421 151953 436270
140430 151...

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
260

result:

wrong answer 1st lines differ - on the 1st token, expected: '451', found: '260'

Subtask #2:

score: 0
Runtime Error

Test #4:

score: 0
Runtime Error

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
50 23 25 382806473
0 1 375710
1 2 898637
2 3 10402
3 4 536577
4 5 385023
5 6 71075
6 7 543368
7 8 301497
8 9 174394
9 10 711312
10 11 923006
11 12 675532
12 13 838667
13 14 565729
14 15 979816
15 16 862618
16 17 576015
17 18 177751
18 19 306989
19 20 881492...

output:


result:


Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Time Limit Exceeded

Test #36:

score: 0
Time Limit Exceeded

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
4 0 1 9
0 2 2
1 2 3
2 3 3

output:


result:


Subtask #6:

score: 0
Skipped

Dependency #2:

0%

Subtask #7:

score: 0
Skipped

Dependency #3:

0%

Subtask #8:

score: 0
Skipped

Dependency #4:

0%

Subtask #9:

score: 0
Skipped

Dependency #1:

0%