Submission #518510

# Submission time Handle Problem Language Result Execution time Memory
518510 2022-01-24T02:03:06 Z tabr Dreaming (IOI13_dreaming) C++17
32 / 100
57 ms 15448 KB
#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

#include "dreaming.h"

template <class F>
struct y_combinator_result {
    F f;

    template <class T>
    explicit y_combinator_result(T &&f_) : f(std::forward<T>(f_)) {}

    template <class... Args>
    decltype(auto) operator()(Args &&...args) {
        return f(std::ref(*this), std::forward<Args>(args)...);
    }
};

template <class F>
decltype(auto) y_combinator(F &&f) {
    return y_combinator_result<std::decay_t<F>>(std::forward<F>(f));
}

int travelTime(int n, int m, int l, int a[], int b[], int w[]) {
    vector<vector<int>> g(n);
    for (int i = 0; i < m; i++) {
        g[a[i]].emplace_back(i);
        g[b[i]].emplace_back(i);
    }
    int ans = 0;
    vector<int> was(n);
    vector<int> dist(n);
    vector<int> c;
    for (int root = 0; root < n; root++) {
        if (was[root]) {
            continue;
        }
        int new_root = root;
        y_combinator([&](auto dfs, int v, int p) -> void {
            was[v] = 1;
            if (dist[new_root] < dist[v]) {
                new_root = v;
            }
            for (int id : g[v]) {
                int to = v ^ a[id] ^ b[id];
                if (to == p) {
                    continue;
                }
                dist[to] = dist[v] + w[id];
                dfs(to, v);
            }
        })(root, -1);
        int t = (int) 2e9;
        dist[new_root] = 0;
        int s = y_combinator([&](auto dfs, int v, int p) -> int {
            int res = dist[v];
            for (int id : g[v]) {
                int to = v ^ a[id] ^ b[id];
                if (to == p) {
                    continue;
                }
                dist[to] = dist[v] + w[id];
                res = max(res, dfs(to, v));
            }
            if (t > max(dist[v], res - dist[v])) {
                t = max(dist[v], res - dist[v]);
            }
            return res;
        })(new_root, -1);
        ans = max(ans, s);
        c.emplace_back(t);
    }
    sort(c.rbegin(), c.rend());
    debug(c);
    if (c.size() > 1) {
        ans = max(ans, c[0] + c[1] + l);
    }
    if (c.size() > 2) {
        ans = max(ans, c[1] + c[2] + l * 2);
    }
    return ans;
}

#ifdef tabr
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a[] = {0, 8, 2, 5, 5, 1, 1, 10};
    int b[] = {8, 2, 7, 11, 1, 3, 9, 6};
    int t[] = {4, 2, 4, 3, 7, 1, 5, 3};
    cout << travelTime(12, 8, 2, a, b, t) << '\n';
    return 0;
}
#endif
# Verdict Execution time Memory Grader output
1 Correct 42 ms 15448 KB Output is correct
2 Correct 42 ms 15420 KB Output is correct
3 Correct 28 ms 10356 KB Output is correct
4 Correct 7 ms 2468 KB Output is correct
5 Correct 5 ms 1484 KB Output is correct
6 Correct 10 ms 3640 KB Output is correct
7 Correct 1 ms 292 KB Output is correct
8 Correct 22 ms 5696 KB Output is correct
9 Correct 27 ms 7832 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 43 ms 10320 KB Output is correct
12 Correct 57 ms 12764 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 42 ms 15448 KB Output is correct
2 Correct 42 ms 15420 KB Output is correct
3 Correct 28 ms 10356 KB Output is correct
4 Correct 7 ms 2468 KB Output is correct
5 Correct 5 ms 1484 KB Output is correct
6 Correct 10 ms 3640 KB Output is correct
7 Correct 1 ms 292 KB Output is correct
8 Correct 22 ms 5696 KB Output is correct
9 Correct 27 ms 7832 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 43 ms 10320 KB Output is correct
12 Correct 57 ms 12764 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 304 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Incorrect 1 ms 204 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 6252 KB Output is correct
2 Correct 22 ms 6308 KB Output is correct
3 Correct 20 ms 6324 KB Output is correct
4 Correct 20 ms 6312 KB Output is correct
5 Correct 20 ms 6328 KB Output is correct
6 Correct 21 ms 6968 KB Output is correct
7 Correct 20 ms 6596 KB Output is correct
8 Correct 20 ms 6320 KB Output is correct
9 Correct 19 ms 6216 KB Output is correct
10 Correct 21 ms 6468 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 5 ms 4016 KB Output is correct
13 Correct 5 ms 4040 KB Output is correct
14 Correct 5 ms 4040 KB Output is correct
15 Correct 5 ms 4092 KB Output is correct
16 Correct 4 ms 4040 KB Output is correct
17 Correct 5 ms 4040 KB Output is correct
18 Correct 5 ms 4124 KB Output is correct
19 Correct 4 ms 4008 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 300 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 5 ms 4040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 42 ms 15448 KB Output is correct
2 Correct 42 ms 15420 KB Output is correct
3 Correct 28 ms 10356 KB Output is correct
4 Correct 7 ms 2468 KB Output is correct
5 Correct 5 ms 1484 KB Output is correct
6 Correct 10 ms 3640 KB Output is correct
7 Correct 1 ms 292 KB Output is correct
8 Correct 22 ms 5696 KB Output is correct
9 Correct 27 ms 7832 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 43 ms 10320 KB Output is correct
12 Correct 57 ms 12764 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 304 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Incorrect 1 ms 204 KB Output isn't correct
17 Halted 0 ms 0 KB -