Submission #785362

# Submission time Handle Problem Language Result Execution time Memory
785362 2023-07-17T08:43:58 Z drdilyor Highway Tolls (IOI18_highway) C++17
51 / 100
285 ms 262144 KB
#include <bits/stdc++.h>
#include "highway.h"
#ifdef ONPC
    #include "t_debug.cpp"
#else
    #define debug(...) 42
#endif
using namespace std;
//namespace pbds = __gnu_pbds;
using ll = long long;
const int inf = 1e9;
const ll infl = 1e18;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(RANDOM);
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p) { return is >> p.first >> p.second; }
template<typename Cont> int sz(const Cont& cont) { return int(cont.size()); }
template<typename Func> struct ycom { Func f; template<typename... T> auto operator()(T&&... args) { return f(*this, args...); } }; template<typename Func> ycom(Func) -> ycom<Func>;
template<typename T> typename vector<T>::iterator operator+(const vector<T>& x, int i) { return x.begin() + i ;};
const string fileio = "";
constexpr int tests = 1, nmax = 2e5, nlog = __lg(nmax), mod = 1e9+7;

void find_pair(int32_t n, std::vector<int32_t> u, std::vector<int32_t> v, int32_t a, int32_t b) {
    int m = u.size();
    vector<vector<pair<int,int>>> adj(n);

    for (int i = 0; i < m; i++) {
        adj[u[i]].emplace_back(v[i], i);
        adj[v[i]].emplace_back(u[i], i);
    }

    ll base = ask(vector(m, 0));
    int len = base / a;

    auto mark_subtree = [&](auto& dfs, vector<int>& w, int i, int p)->void{
        for (auto[e, ei] : adj[i]) {
            if (e == p) continue;
            w[ei] = 1;
            dfs(dfs, w, e, i);
        }
    };

    auto find_path_from_root = [&](int root, int p, int len) {
        if (len == 0) {
            return root;
        }

        vector<pair<int,int>> level;
        auto dfs = [&](auto& dfs, int i, int p, int dep)->void{
            for (auto [e, ei] : adj[i]) {
                if (e == p) continue;
                if (dep+1 == len) {
                    level.emplace_back(e, ei);
                    continue;
                }
                dfs(dfs, e, i, dep+1);
            }
        };
        dfs(dfs, root, p, 0);

        int l = 0, r = level.size()-1;
        while (l < r) {
            int mid = (l + r) / 2;
            vector<int> w(m);
            for (int i = l; i <= mid; i++) {
                w[level[i].second] = 1;
            }
            ll toll = ask(w);
            assert(toll == base || toll == base - a + b);
            if (toll == base) {
                l = mid+1;
            } else r = mid;
        }
        return level[l].first;
    };

    int l = 0, r = m-1;
    while (l < r) {
        int mid = (l + r) / 2;
        vector<int> w(m);
        fill(w.begin() + l, w.begin() + mid+1, 1);
        ll toll = ask(w);
        if (toll == base) l = mid+1;
        else r = mid;
    }


    int left = u[l];
    int right = v[l];

    vector<int> w(m);
    mark_subtree(mark_subtree, w, left, right);
    int left_len = (ask(w) - base) / (b - a);

    answer(
            find_path_from_root(left, right, left_len),
            find_path_from_root(right, left, len - left_len - 1)
            );
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 12 ms 1104 KB Output is correct
3 Correct 117 ms 8168 KB Output is correct
4 Correct 105 ms 8096 KB Output is correct
5 Correct 81 ms 8024 KB Output is correct
6 Correct 65 ms 7904 KB Output is correct
7 Correct 80 ms 8044 KB Output is correct
8 Correct 110 ms 7920 KB Output is correct
9 Correct 118 ms 7920 KB Output is correct
10 Correct 74 ms 8100 KB Output is correct
11 Correct 73 ms 7656 KB Output is correct
12 Correct 94 ms 7956 KB Output is correct
13 Correct 80 ms 7524 KB Output is correct
14 Correct 82 ms 7880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1048 KB Output is correct
2 Correct 15 ms 1848 KB Output is correct
3 Correct 34 ms 3144 KB Output is correct
4 Correct 71 ms 7792 KB Output is correct
5 Correct 96 ms 7800 KB Output is correct
6 Correct 76 ms 9036 KB Output is correct
7 Correct 83 ms 9148 KB Output is correct
8 Correct 54 ms 8044 KB Output is correct
9 Correct 72 ms 8624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 8 ms 1116 KB Output is correct
3 Correct 46 ms 6184 KB Output is correct
4 Correct 84 ms 7996 KB Output is correct
5 Correct 74 ms 7840 KB Output is correct
6 Correct 79 ms 7804 KB Output is correct
7 Correct 86 ms 7844 KB Output is correct
8 Correct 58 ms 7784 KB Output is correct
9 Correct 96 ms 8156 KB Output is correct
10 Correct 83 ms 8160 KB Output is correct
11 Correct 114 ms 7900 KB Output is correct
12 Correct 99 ms 7872 KB Output is correct
13 Correct 103 ms 7852 KB Output is correct
14 Correct 116 ms 7876 KB Output is correct
15 Correct 98 ms 7856 KB Output is correct
16 Correct 68 ms 7548 KB Output is correct
17 Correct 101 ms 7828 KB Output is correct
18 Correct 105 ms 7924 KB Output is correct
19 Correct 74 ms 7784 KB Output is correct
20 Correct 98 ms 7488 KB Output is correct
21 Correct 97 ms 9156 KB Output is correct
22 Correct 78 ms 9212 KB Output is correct
23 Correct 83 ms 8580 KB Output is correct
24 Correct 83 ms 8612 KB Output is correct
25 Correct 81 ms 10336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 285 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 178 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -