Submission #980942

# Submission time Handle Problem Language Result Execution time Memory
980942 2024-05-12T16:01:20 Z RedGrey1993 JOI tour (JOI24_joitour) C++17
100 / 100
601 ms 204432 KB
#include "joitour.h"
#include <bits/stdc++.h>

using namespace std;
 
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &pa) { is >> pa.first >> pa.second; return is; }
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa) { os << "(" << pa.first << "," << pa.second << ")"; return os; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template <typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp) { os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template <typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp) { os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template <typename T> void resize_array(vector<T> &vec, int len) { vec.resize(len); }
template <typename T, typename... Args> void resize_array(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) resize_array(v, args...); }
template <typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template <typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }
 
#define rep(i, a, n) for (int i = a; i < (n); i++)
#define per(i, a, n) for (int i = (n)-1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef double db;
#if DEBUG
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;
#else
#define dbg(x)
#endif

template <typename T>
class StaticTopTree {
 public:
  enum Type { Vertex, Compress, Rake, AddEdge, AddVertex };
  StaticTopTree(vector<vector<int>> &g, int root = 0) : g_(g), root_(root) {
    int n = g_.size();
    parent_.resize(4 * n, -1);
    left_.resize(4 * n, -1);
    right_.resize(4 * n, -1);
    vertex_type_.resize(4 * n, Type::Vertex);
    paths_.resize(4 * n);
    points_.resize(4 * n);
    cur_idx_ = n;
    build();
  }

 private:
  // do HLD(Heavy Light Decomposition), move heavy edge to g_[c][0];
  int dfs(int c) {
    int s = 1, best = 0;
    for (int &d : g_[c]) {
      int t = dfs(d);
      s += t;
      if (best < t) best = t, swap(d, g_[c][0]);
    }
    return s;
  }
  int add(int k, int l, int r, Type t) {
    if (k == -1) k = cur_idx_++;
    parent_[k] = -1, left_[k] = l, right_[k] = r, vertex_type_[k] = t;
    if (l != -1) parent_[l] = k;
    if (r != -1) parent_[r] = k;
    return k;
  }
  pair<int, int> merge(const vector<pair<int, int>> &a, Type t) {
    if (a.size() == 1) return a[0];
    int u = 0;
    for (auto &[_, s] : a) u += s;
    vector<pair<int, int>> b, c;
    // make sure b/c at least has 1 item
    for (auto& [i, s] : a) (u > s ? b : c).emplace_back(i, s), u -= s * 2;
    // if use (u > 0 ? b : c), c may be 0 size, will be RE
    // for (auto &[i, s] : a) (u > 0 ? b : c).emplace_back(i, s), u -= s * 2;
    auto [i, si] = merge(b, t);
    auto [j, sj] = merge(c, t);
    return {add(-1, i, j, t), si + sj};
  }
  pair<int, int> compress(int i) {
    vector<pair<int, int>> chs{add_vertex(i)};
    while (!g_[i].empty()) chs.push_back(add_vertex(i = g_[i][0]));
    return merge(chs, Type::Compress);
  }
  pair<int, int> rake(int i) {
    vector<pair<int, int>> chs;
    for (int j = 1; j < (int)g_[i].size(); j++)
      chs.push_back(add_edge(g_[i][j]));
    return chs.empty() ? make_pair(-1, 0) : merge(chs, Type::Rake);
  }
  pair<int, int> add_edge(int i) {
    auto [j, sj] = compress(i);
    return {add(-1, j, -1, Type::AddEdge), sj};
  }
  pair<int, int> add_vertex(int i) {
    auto [j, sj] = rake(i);
    return {add(i, j, -1, j == -1 ? Type::Vertex : Type::AddVertex), sj + 1};
  }
  void build() {
    dfs(root_);
    auto [i, n] = compress(root_);
    stt_root_ = i;
  }
  // private:
 public:
  // adjacent list of initial tree, chridren are stored in g_[parent],
  // parent can not be stored in g_[child] in this implement!!!
  // g_ must be a rooted tree
  vector<vector<int>> &g_;
  int root_;      // an index of the root in g
  int stt_root_;  // an index of the root in static top tree
  vector<int> parent_, left_, right_;  // parent, left child, right child
  vector<Type> vertex_type_;           // type of vertices
  int cur_idx_;                        // a variable for the index increment

  vector<int> values;

 private:
  // u: upper boundary vertex, v: lower boundary vertex
  struct TP {
    // ll fv;
    ll c012,c01u,c2,c0,cu12,c01v,cv12,cu1v,c0_u_2,cvu_2,c0_uv;
    friend ostream &operator<<(ostream &os, const TP &p) { 
      return os << "c012:" << p.c012 << "\n"
                << "c01u:" << p.c01u << "\n"
                << "c2:" << p.c2 << "\n"
                << "c0:" << p.c0 << "\n"
                << "cu12:" << p.cu12 << "\n"
                << "c01v:" << p.c01v << "\n"
                << "cv12:" << p.cv12 << "\n"
                << "cu1v:" << p.cu1v << "\n"
                << "c0_u_2:" << p.c0_u_2 << "\n"
                << "cvu_2:" << p.cvu_2 << "\n"
                << "c0_uv:" << p.c0_uv << "\n"; 
    }
  };
  using Point = TP;
  using Path = TP;
  vector<Point> points_;
  vector<Path> paths_;
  Path vertex(int i) { 
    TP tp;
    // tp.fv= values[i];
    tp.c012 = 0;
    tp.c01u = 0;
    tp.c2 = (values[i] == 2);
    tp.c0 = (values[i] == 0);
    tp.cu12 = 0;
    tp.c01v = 0;
    tp.cv12 = 0;
    tp.cu1v = (values[i] == 1);
    tp.c0_u_2 = 0;
    tp.cvu_2 = 0;
    tp.c0_uv = 0;
    return tp; 
  }
  Path compress(Path p, Path c) { 
    TP tp;
    // tp.fv = c.fv;
    tp.c012 = p.c012 + c.c012 + p.c01v * c.c2 + p.cv12 * c.c0 + p.c0 * c.cu12 + p.c2 * c.c01u;
    tp.c01u = p.c01u + c.c01u + p.cu1v * c.c0;
    tp.c2 = p.c2 + c.c2;
    tp.c0 = p.c0 + c.c0;
    tp.cu12 = p.cu12 + c.cu12 + p.cu1v * c.c2;
    tp.c01v = p.c01v + c.c01v + p.c0 * c.cu1v;
    tp.cv12 = p.cv12 + c.cv12 + p.c2 * c.cu1v;
    tp.cu1v = p.cu1v + c.cu1v;
    tp.c0_u_2 = p.c0_u_2 + c.c0 * p.cvu_2 + c.c2 * p.c0_uv;
    tp.cvu_2 = p.cvu_2;
    tp.c0_uv = p.c0_uv;
    return tp;
  }
  Path add_vertex(Point p, int i) { 
    TP tp;
    // tp.fv = values[i];
    tp.c012 = p.c012 + p.cu12 * (values[i] == 0) + p.c01u * (values[i] == 2) + p.c0_u_2 * (values[i] == 1);
    tp.c01u = p.c01u + p.c0 * (values[i] == 1);
    tp.c2 = p.c2 + (values[i] == 2);
    tp.c0 = p.c0 + (values[i] == 0);
    tp.cu12 = p.cu12 + (values[i] == 1) * p.c2;
    tp.c01v = p.c01u + (values[i] == 1) * p.c0;
    tp.cv12 = p.cu12 + (values[i] == 1) * p.c2;
    tp.cu1v = (values[i] == 1);
    tp.c0_u_2 = p.c0_u_2;
    tp.cvu_2 = p.c2;
    tp.c0_uv = p.c0;
    return tp;
  }
  Point add_edge(Path p) {
    TP tp = p;
    tp.cu1v = 0;
    tp.c0_u_2 = 0;
    tp.cvu_2 = 0;
    tp.c0_uv = 0;
    return tp;
  }
  Point rake(Point p, Point c) {
    TP tp;
    // tp.fv = values[i];
    tp.c012 = p.c012 + c.c012 + p.c01u * c.c2 + p.cu12 * c.c0 + p.c2 * c.c01u + p.c0 * c.cu12;
    tp.c01u = p.c01u + c.c01u;
    tp.c2 = p.c2 + c.c2;
    tp.c0 = p.c0 + c.c0;
    tp.cu12 = p.cu12 + c.cu12;
    tp.c01v = p.c01u + c.c01u;
    tp.cv12 = p.cu12 + c.cu12;
    tp.cu1v = 0;
    tp.c0_u_2 = p.c0_u_2 + c.c0_u_2 + p.c0 * c.c2 + p.c2 * c.c0;
    // tp.cvu_2 = 0;
    // tp.c0_uv = 0;
    return tp;
  }

  void update_node(int k) {
    if (vertex_type_[k] == Vertex) paths_[k] = vertex(k);
    else if (vertex_type_[k] == Compress) paths_[k] = compress(paths_[left_[k]], paths_[right_[k]]);
    else if (vertex_type_[k] == AddVertex) paths_[k] = add_vertex(points_[left_[k]], k);
    else if (vertex_type_[k] == AddEdge) points_[k] = add_edge(paths_[left_[k]]);
    else if (vertex_type_[k] == Rake) points_[k] = rake(points_[left_[k]], points_[right_[k]]);
  }

  void init(int k) {
    if (left_[k] != -1) init(left_[k]);
    if (right_[k] != -1) init(right_[k]);
    update_node(k);
    dbg(mp(k, vertex_type_[k]));
    dbg(points_[k]);
    dbg(paths_[k]);
  }

 public:
  void update_tree(int k, T v) {
    values[k] = v;
    while (k != -1) {
      update_node(k);
      k = parent_[k];
    }
  }

  void init() {
    init(stt_root_);
  }

  T get_answer() {
    return paths_[stt_root_].c012;
  }
};

unique_ptr<StaticTopTree<ll>> p_stt = nullptr;

void init(int N, std::vector<int> F, std::vector<int> U, std::vector<int> V, int Q) {
  vector<vi> edges(N);

  rep(i,0,N-1) {
    edges[U[i]].emplace_back(V[i]);
    edges[V[i]].emplace_back(U[i]);
  }
  vector<vi> g(N);
  function<void(int,int)> dfs=[&] (int u, int p) {
    for(int v : edges[u]) {
      if (v != p) {
        g[u].emplace_back(v);
        dfs(v, u);
      }
    }
  };
  dfs(0, -1);
  dbg(g);

  p_stt = make_unique<StaticTopTree<ll>>(g);
  p_stt->values = F;
  dbg(p_stt->values);
  p_stt->init();
}

void change(int X, int Y) {
  p_stt->update_tree(X, Y);
}

long long num_tours() {
  return p_stt->get_answer();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 856 KB Output is correct
10 Correct 1 ms 856 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 408 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 856 KB Output is correct
10 Correct 1 ms 856 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 408 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 8 ms 4440 KB Output is correct
26 Correct 8 ms 3996 KB Output is correct
27 Correct 8 ms 4184 KB Output is correct
28 Correct 9 ms 4280 KB Output is correct
29 Correct 7 ms 4184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 540 KB Output is correct
2 Correct 290 ms 194408 KB Output is correct
3 Correct 229 ms 193520 KB Output is correct
4 Correct 218 ms 188944 KB Output is correct
5 Correct 235 ms 195524 KB Output is correct
6 Correct 119 ms 175316 KB Output is correct
7 Correct 115 ms 175320 KB Output is correct
8 Correct 188 ms 174436 KB Output is correct
9 Correct 204 ms 175340 KB Output is correct
10 Correct 202 ms 175256 KB Output is correct
11 Correct 185 ms 175976 KB Output is correct
12 Correct 213 ms 182352 KB Output is correct
13 Correct 195 ms 182588 KB Output is correct
14 Correct 193 ms 182188 KB Output is correct
15 Correct 207 ms 181132 KB Output is correct
16 Correct 224 ms 198852 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 253 ms 175832 KB Output is correct
22 Correct 188 ms 175832 KB Output is correct
23 Correct 228 ms 175904 KB Output is correct
24 Correct 196 ms 175836 KB Output is correct
25 Correct 155 ms 177480 KB Output is correct
26 Correct 183 ms 177480 KB Output is correct
27 Correct 155 ms 177624 KB Output is correct
28 Correct 155 ms 177480 KB Output is correct
29 Correct 151 ms 204432 KB Output is correct
30 Correct 159 ms 204116 KB Output is correct
31 Correct 156 ms 204300 KB Output is correct
32 Correct 142 ms 204112 KB Output is correct
33 Correct 113 ms 174812 KB Output is correct
34 Correct 113 ms 175004 KB Output is correct
35 Correct 118 ms 175004 KB Output is correct
36 Correct 115 ms 174804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 1112 KB Output is correct
8 Correct 7 ms 4576 KB Output is correct
9 Correct 142 ms 204300 KB Output is correct
10 Correct 141 ms 204368 KB Output is correct
11 Correct 157 ms 204116 KB Output is correct
12 Correct 146 ms 204208 KB Output is correct
13 Correct 203 ms 102336 KB Output is correct
14 Correct 203 ms 102320 KB Output is correct
15 Correct 223 ms 102340 KB Output is correct
16 Correct 240 ms 102512 KB Output is correct
17 Correct 215 ms 102344 KB Output is correct
18 Correct 220 ms 102264 KB Output is correct
19 Correct 461 ms 204100 KB Output is correct
20 Correct 428 ms 204304 KB Output is correct
21 Correct 452 ms 204112 KB Output is correct
22 Correct 448 ms 204112 KB Output is correct
23 Correct 475 ms 204112 KB Output is correct
24 Correct 424 ms 204232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 8 ms 4184 KB Output is correct
8 Correct 120 ms 175072 KB Output is correct
9 Correct 115 ms 175020 KB Output is correct
10 Correct 117 ms 174808 KB Output is correct
11 Correct 114 ms 174928 KB Output is correct
12 Correct 218 ms 87692 KB Output is correct
13 Correct 254 ms 87612 KB Output is correct
14 Correct 244 ms 87612 KB Output is correct
15 Correct 241 ms 87556 KB Output is correct
16 Correct 228 ms 87516 KB Output is correct
17 Correct 215 ms 87624 KB Output is correct
18 Correct 400 ms 175004 KB Output is correct
19 Correct 494 ms 174808 KB Output is correct
20 Correct 487 ms 174812 KB Output is correct
21 Correct 449 ms 174808 KB Output is correct
22 Correct 484 ms 175000 KB Output is correct
23 Correct 469 ms 174812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 856 KB Output is correct
10 Correct 1 ms 856 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 408 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 8 ms 4440 KB Output is correct
26 Correct 8 ms 3996 KB Output is correct
27 Correct 8 ms 4184 KB Output is correct
28 Correct 9 ms 4280 KB Output is correct
29 Correct 7 ms 4184 KB Output is correct
30 Correct 218 ms 94628 KB Output is correct
31 Correct 234 ms 96116 KB Output is correct
32 Correct 265 ms 96372 KB Output is correct
33 Correct 231 ms 97544 KB Output is correct
34 Correct 286 ms 98112 KB Output is correct
35 Correct 261 ms 95952 KB Output is correct
36 Correct 215 ms 87656 KB Output is correct
37 Correct 218 ms 87872 KB Output is correct
38 Correct 256 ms 87268 KB Output is correct
39 Correct 246 ms 87740 KB Output is correct
40 Correct 259 ms 87612 KB Output is correct
41 Correct 231 ms 88304 KB Output is correct
42 Correct 248 ms 91328 KB Output is correct
43 Correct 256 ms 90056 KB Output is correct
44 Correct 261 ms 90600 KB Output is correct
45 Correct 259 ms 91240 KB Output is correct
46 Correct 270 ms 90368 KB Output is correct
47 Correct 246 ms 91668 KB Output is correct
48 Correct 239 ms 97336 KB Output is correct
49 Correct 251 ms 99604 KB Output is correct
50 Correct 236 ms 96324 KB Output is correct
51 Correct 224 ms 88216 KB Output is correct
52 Correct 285 ms 88316 KB Output is correct
53 Correct 249 ms 88128 KB Output is correct
54 Correct 262 ms 88072 KB Output is correct
55 Correct 249 ms 88144 KB Output is correct
56 Correct 239 ms 88144 KB Output is correct
57 Correct 195 ms 89020 KB Output is correct
58 Correct 224 ms 89028 KB Output is correct
59 Correct 228 ms 89032 KB Output is correct
60 Correct 231 ms 89024 KB Output is correct
61 Correct 225 ms 89020 KB Output is correct
62 Correct 220 ms 102220 KB Output is correct
63 Correct 243 ms 102324 KB Output is correct
64 Correct 218 ms 102328 KB Output is correct
65 Correct 242 ms 102320 KB Output is correct
66 Correct 226 ms 102324 KB Output is correct
67 Correct 242 ms 102324 KB Output is correct
68 Correct 197 ms 87720 KB Output is correct
69 Correct 247 ms 87520 KB Output is correct
70 Correct 252 ms 87648 KB Output is correct
71 Correct 213 ms 87612 KB Output is correct
72 Correct 266 ms 87628 KB Output is correct
73 Correct 225 ms 87628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 856 KB Output is correct
10 Correct 1 ms 856 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 408 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 8 ms 4440 KB Output is correct
26 Correct 8 ms 3996 KB Output is correct
27 Correct 8 ms 4184 KB Output is correct
28 Correct 9 ms 4280 KB Output is correct
29 Correct 7 ms 4184 KB Output is correct
30 Correct 1 ms 540 KB Output is correct
31 Correct 290 ms 194408 KB Output is correct
32 Correct 229 ms 193520 KB Output is correct
33 Correct 218 ms 188944 KB Output is correct
34 Correct 235 ms 195524 KB Output is correct
35 Correct 119 ms 175316 KB Output is correct
36 Correct 115 ms 175320 KB Output is correct
37 Correct 188 ms 174436 KB Output is correct
38 Correct 204 ms 175340 KB Output is correct
39 Correct 202 ms 175256 KB Output is correct
40 Correct 185 ms 175976 KB Output is correct
41 Correct 213 ms 182352 KB Output is correct
42 Correct 195 ms 182588 KB Output is correct
43 Correct 193 ms 182188 KB Output is correct
44 Correct 207 ms 181132 KB Output is correct
45 Correct 224 ms 198852 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
47 Correct 0 ms 344 KB Output is correct
48 Correct 0 ms 344 KB Output is correct
49 Correct 0 ms 344 KB Output is correct
50 Correct 253 ms 175832 KB Output is correct
51 Correct 188 ms 175832 KB Output is correct
52 Correct 228 ms 175904 KB Output is correct
53 Correct 196 ms 175836 KB Output is correct
54 Correct 155 ms 177480 KB Output is correct
55 Correct 183 ms 177480 KB Output is correct
56 Correct 155 ms 177624 KB Output is correct
57 Correct 155 ms 177480 KB Output is correct
58 Correct 151 ms 204432 KB Output is correct
59 Correct 159 ms 204116 KB Output is correct
60 Correct 156 ms 204300 KB Output is correct
61 Correct 142 ms 204112 KB Output is correct
62 Correct 113 ms 174812 KB Output is correct
63 Correct 113 ms 175004 KB Output is correct
64 Correct 118 ms 175004 KB Output is correct
65 Correct 115 ms 174804 KB Output is correct
66 Correct 0 ms 344 KB Output is correct
67 Correct 0 ms 344 KB Output is correct
68 Correct 1 ms 344 KB Output is correct
69 Correct 1 ms 344 KB Output is correct
70 Correct 1 ms 344 KB Output is correct
71 Correct 1 ms 344 KB Output is correct
72 Correct 1 ms 1112 KB Output is correct
73 Correct 7 ms 4576 KB Output is correct
74 Correct 142 ms 204300 KB Output is correct
75 Correct 141 ms 204368 KB Output is correct
76 Correct 157 ms 204116 KB Output is correct
77 Correct 146 ms 204208 KB Output is correct
78 Correct 203 ms 102336 KB Output is correct
79 Correct 203 ms 102320 KB Output is correct
80 Correct 223 ms 102340 KB Output is correct
81 Correct 240 ms 102512 KB Output is correct
82 Correct 215 ms 102344 KB Output is correct
83 Correct 220 ms 102264 KB Output is correct
84 Correct 461 ms 204100 KB Output is correct
85 Correct 428 ms 204304 KB Output is correct
86 Correct 452 ms 204112 KB Output is correct
87 Correct 448 ms 204112 KB Output is correct
88 Correct 475 ms 204112 KB Output is correct
89 Correct 424 ms 204232 KB Output is correct
90 Correct 0 ms 344 KB Output is correct
91 Correct 1 ms 344 KB Output is correct
92 Correct 1 ms 344 KB Output is correct
93 Correct 1 ms 340 KB Output is correct
94 Correct 1 ms 344 KB Output is correct
95 Correct 1 ms 600 KB Output is correct
96 Correct 8 ms 4184 KB Output is correct
97 Correct 120 ms 175072 KB Output is correct
98 Correct 115 ms 175020 KB Output is correct
99 Correct 117 ms 174808 KB Output is correct
100 Correct 114 ms 174928 KB Output is correct
101 Correct 218 ms 87692 KB Output is correct
102 Correct 254 ms 87612 KB Output is correct
103 Correct 244 ms 87612 KB Output is correct
104 Correct 241 ms 87556 KB Output is correct
105 Correct 228 ms 87516 KB Output is correct
106 Correct 215 ms 87624 KB Output is correct
107 Correct 400 ms 175004 KB Output is correct
108 Correct 494 ms 174808 KB Output is correct
109 Correct 487 ms 174812 KB Output is correct
110 Correct 449 ms 174808 KB Output is correct
111 Correct 484 ms 175000 KB Output is correct
112 Correct 469 ms 174812 KB Output is correct
113 Correct 218 ms 94628 KB Output is correct
114 Correct 234 ms 96116 KB Output is correct
115 Correct 265 ms 96372 KB Output is correct
116 Correct 231 ms 97544 KB Output is correct
117 Correct 286 ms 98112 KB Output is correct
118 Correct 261 ms 95952 KB Output is correct
119 Correct 215 ms 87656 KB Output is correct
120 Correct 218 ms 87872 KB Output is correct
121 Correct 256 ms 87268 KB Output is correct
122 Correct 246 ms 87740 KB Output is correct
123 Correct 259 ms 87612 KB Output is correct
124 Correct 231 ms 88304 KB Output is correct
125 Correct 248 ms 91328 KB Output is correct
126 Correct 256 ms 90056 KB Output is correct
127 Correct 261 ms 90600 KB Output is correct
128 Correct 259 ms 91240 KB Output is correct
129 Correct 270 ms 90368 KB Output is correct
130 Correct 246 ms 91668 KB Output is correct
131 Correct 239 ms 97336 KB Output is correct
132 Correct 251 ms 99604 KB Output is correct
133 Correct 236 ms 96324 KB Output is correct
134 Correct 224 ms 88216 KB Output is correct
135 Correct 285 ms 88316 KB Output is correct
136 Correct 249 ms 88128 KB Output is correct
137 Correct 262 ms 88072 KB Output is correct
138 Correct 249 ms 88144 KB Output is correct
139 Correct 239 ms 88144 KB Output is correct
140 Correct 195 ms 89020 KB Output is correct
141 Correct 224 ms 89028 KB Output is correct
142 Correct 228 ms 89032 KB Output is correct
143 Correct 231 ms 89024 KB Output is correct
144 Correct 225 ms 89020 KB Output is correct
145 Correct 220 ms 102220 KB Output is correct
146 Correct 243 ms 102324 KB Output is correct
147 Correct 218 ms 102328 KB Output is correct
148 Correct 242 ms 102320 KB Output is correct
149 Correct 226 ms 102324 KB Output is correct
150 Correct 242 ms 102324 KB Output is correct
151 Correct 197 ms 87720 KB Output is correct
152 Correct 247 ms 87520 KB Output is correct
153 Correct 252 ms 87648 KB Output is correct
154 Correct 213 ms 87612 KB Output is correct
155 Correct 266 ms 87628 KB Output is correct
156 Correct 225 ms 87628 KB Output is correct
157 Correct 564 ms 192108 KB Output is correct
158 Correct 564 ms 193608 KB Output is correct
159 Correct 567 ms 191500 KB Output is correct
160 Correct 560 ms 189324 KB Output is correct
161 Correct 553 ms 195004 KB Output is correct
162 Correct 591 ms 194860 KB Output is correct
163 Correct 469 ms 175320 KB Output is correct
164 Correct 487 ms 175328 KB Output is correct
165 Correct 551 ms 174404 KB Output is correct
166 Correct 582 ms 175096 KB Output is correct
167 Correct 566 ms 175068 KB Output is correct
168 Correct 582 ms 176096 KB Output is correct
169 Correct 484 ms 181908 KB Output is correct
170 Correct 506 ms 180540 KB Output is correct
171 Correct 570 ms 180756 KB Output is correct
172 Correct 538 ms 179888 KB Output is correct
173 Correct 519 ms 181516 KB Output is correct
174 Correct 587 ms 182360 KB Output is correct
175 Correct 526 ms 193348 KB Output is correct
176 Correct 567 ms 197680 KB Output is correct
177 Correct 581 ms 203144 KB Output is correct
178 Correct 486 ms 175832 KB Output is correct
179 Correct 601 ms 176088 KB Output is correct
180 Correct 567 ms 175844 KB Output is correct
181 Correct 548 ms 176024 KB Output is correct
182 Correct 523 ms 176016 KB Output is correct
183 Correct 547 ms 176276 KB Output is correct
184 Correct 443 ms 177632 KB Output is correct
185 Correct 497 ms 177568 KB Output is correct
186 Correct 505 ms 177452 KB Output is correct
187 Correct 491 ms 177560 KB Output is correct
188 Correct 518 ms 177728 KB Output is correct