QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#789171#7588. Monster HunterMaraschinoCompile Error//C++143.1kb2024-11-27 19:27:402024-11-27 19:27:40

Judging History

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

  • [2024-11-27 19:27:40]
  • 评测
  • [2024-11-27 19:27:40]
  • 提交

answer

#include <bits/stdc++.h>
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define ep emplace
#define eb emplace_back
#define all(x) x.begin(), x.end()
FILE *fin, *fout, *ferr;
i32 read() {
  i32 t = 0, f = 0;
  char ch = fgetc(fin);
  for (; !isdigit(ch); ch = fgetc(fin)) f ^= (ch == '-');
  for (; isdigit(ch); ch = fgetc(fin)) t = (t << 1) + (t << 3) + (ch ^ 48);
  return f ? -t : t;
}
template<typename T1, typename T2>
constexpr bool chkmax(T1 &a, T2 b) { return a > b ? false : (a = b, true); } 
template<typename T1, typename T2>
constexpr bool chkmin(T1 &a, T2 b) { return a > b ? (a = b, true) : false; } 
namespace Solution_Of_C24204 {
  bool _1;
  static const i32 N = 1000005;
  i32 n;
  struct Node {
    i64 a, b, c, d;
    Node() = default;
    Node(i64 a, i64 b, i64 c, i32 d): a(a), b(b), c(c), d(d) {}
    bool operator<(const Node &a) const {
      if ((this->c <= 0) != (a.c <= 0)) return this->c > a.c;
      if (this->c < 0) return this->b != a.b ? this->b > a.b : (this->a != a.a ? this->a < a.a : this->d < a.d);
      if (this->c >= 0) return this->a != a.a ? this->a < a.a : (this->b != a.b ? this->b > a.b : this->d < a.d); 
      assert(0);
      return true;
    }
  };
  i64 a[N], b[N];
  i32 fa[N], fat[N], vis[N];
  std::vector<i32> e[N];
  std::set<Node> s;
  bool flag;
  bool _2;
  i32 find(i32 x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
  void dfs(i32 x, i32 f) {
    fat[x] = f;
    for (i32 y : e[x])
      if (y != f)
        dfs(y, x);
    return void();
  }
  void solve() {
    n = read();
    for (i32 i = 2; i <= n; ++i) a[i] = read(), b[i] = read();
    for (i32 i = 1; i <= n; ++i) vis[i] = false;
    vis[1] = true;
    for (i32 i = 1; i <= n; ++i) fa[i] = i;
    for (i32 i = 1; i < n; ++i) {
      static i32 u, v;
      u = read(), v = read();
      e[u].eb(v), e[v].eb(u);
    }
    dfs(1, 0);
    for (i32 i = 2; i <= n; ++i) s.ep(Node(a[i], b[i], b[i] - a[i], i));
    i64 now = 0, ans = 0;
    if (flag) exit(0);
    for (i32 i = 1; i < n; ++i) {
      auto [A, B, C, D] = *s.begin();
      s.erase(s.begin());
      i32 u = find(fat[D]);
      if (vis[u]) {
        now += A;
        ans = std::max(ans, now);
        now -= B;
        vis[D] = true;
      } else {
        fa[D] = u;
        assert(s.find({a[u], b[u], b[u] - a[u], u} != s.end());
        s.erase(s.find({a[u], b[u], b[u] - a[u], u}));
        if (A > b[u]) {
          a[u] = a[u] + A - b[u];
          b[u] = B;
        } else {
          a[u] = a[u];
          b[u] = B + b[u] - A;
        }
        s.ep(a[u], b[u], b[u] - a[u], u);
      }
    }
    fprintf(fout, "%lld\n", ans);
    return void();
  }
  void main() {
    fin = stdin, fout = stdout, ferr = stderr;
    fprintf(ferr, "%.2lf MB memory\n", 1.0 * (&_1 - &_2) / 1024 / 1024);
    i64 Start_Time = clock();
    i32 t = read();
    while (t--) {
      solve();
      flag = true;
    }
    i64 End_Time = clock();
    fprintf(ferr, "%lld ms time\n", End_Time - Start_Time);
    return void();
  }
}
signed main() { return Solution_Of_C24204::main(), 0; }

Details

answer.code:107:56: error: unterminated argument list invoking macro "assert"
  107 | signed main() { return Solution_Of_C24204::main(), 0; }
      |                                                        ^
answer.code: In function ‘void Solution_Of_C24204::solve()’:
answer.code:68:12: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   68 |       auto [A, B, C, D] = *s.begin();
      |            ^
answer.code:78:9: error: ‘assert’ was not declared in this scope
   78 |         assert(s.find({a[u], b[u], b[u] - a[u], u} != s.end());
      |         ^~~~~~
answer.code:2:1: note: ‘assert’ is defined in header ‘<cassert>’; did you forget to ‘#include <cassert>’?
    1 | #include <bits/stdc++.h>
  +++ |+#include <cassert>
    2 | using i16 = int16_t;
answer.code:78:15: error: expected ‘}’ at end of input
   78 |         assert(s.find({a[u], b[u], b[u] - a[u], u} != s.end());
      |               ^
answer.code:76:14: note: to match this ‘{’
   76 |       } else {
      |              ^
answer.code:78:15: error: expected ‘}’ at end of input
   78 |         assert(s.find({a[u], b[u], b[u] - a[u], u} != s.end());
      |               ^
answer.code:67:33: note: to match this ‘{’
   67 |     for (i32 i = 1; i < n; ++i) {
      |                                 ^
answer.code:78:15: error: expected ‘}’ at end of input
   78 |         assert(s.find({a[u], b[u], b[u] - a[u], u} != s.end());
      |               ^
answer.code:52:16: note: to match this ‘{’
   52 |   void solve() {
      |                ^
answer.code: At global scope:
answer.code:78:15: error: expected ‘}’ at end of input
   78 |         assert(s.find({a[u], b[u], b[u] - a[u], u} != s.end());
      |               ^
answer.code:22:30: note: to match this ‘{’
   22 | namespace Solution_Of_C24204 {
      |                              ^