Submission #841800

# Submission time Handle Problem Language Result Execution time Memory
841800 2023-09-02T06:20:31 Z grt Closing Time (IOI23_closing) C++17
43 / 100
121 ms 33744 KB
//GRT_2018
#include <bits/stdc++.h>
#define PB push_back
#define ST first
#define ND second
#define all(x) x.begin(), x.end()
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

using namespace std;

using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;

const int nax = 200 * 1000 + 10;
int n, endX, endY;
vector<pi> V[nax];
pair<ll,ll> dist[nax];

void dfs(int x, int par, int bit) {
    for (auto [y, w] : V[x]) {
        if (y == par) continue;
        if (bit == 0) dist[y].ST = dist[x].ST + w;
        else dist[y].ND = dist[x].ND + w;
        dfs(y, x, bit);
    }
}

int max_score(int N, int x, int y, ll k, vi u, vi v, vi w) {
    n = N;
    endX = x;
    endY = y;
    for (int i = 0; i < n; ++i) {
        V[i].clear();
    }
    for (int i = 0; i < n - 1; ++i) {
        V[u[i]].emplace_back(v[i], w[i]);
        V[v[i]].emplace_back(u[i], w[i]);
    }
    dist[endX].ST = 0;
    dfs(endX, -1, 0);
    dist[endY].ND = 0;
    dfs(endY, -1, 1);
    ll d = dist[endY].ST;


    for (int i = 0; i < n; ++i) {
        if (dist[i].ST > dist[i].ND) {
            swap(dist[i].ST, dist[i].ND);
        }
    }
    sort(dist, dist + n);

    int ans = 0;
    ll s = 0;
    for (int i = 0; i < n; ++i) {
        s += dist[i].ST;
        if (s <= k) ans = max(ans, i + 1);
        swap(dist[i].ST, dist[i].ND);
    }
    sort(dist, dist + n);
    int cur = 0;
    multiset<ll>ext;

    for (int i = 0; i < n; ++i) {
        if (dist[i].ST + dist[i].ND == d) {
            cur++;
            k -= dist[i].ND;
        } else {
            ext.insert(dist[i].ND);
        }
    }
    if (k < 0) return ans;

    s = 0;
    for (int i = 0; i < n; ++i) {
        if (dist[i].ST + dist[i].ND == d) {
            s += dist[i].ST - dist[i].ND;
            cur++;
        } else {
            s += dist[i].ST;
            cur += 2;
            ext.erase(ext.find(dist[i].ND));
        }
        ll s2 = 0;
        int add = 0;
        for (auto it : ext) {
            if (s + s2 + it <= k) {
                add++;
                s2 += it;
            } else {
                break;
            }
        }
        if (s <= k) {
            ans = max(ans, cur + add);
        }
    }

    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 121 ms 31904 KB Output is correct
2 Correct 118 ms 33744 KB Output is correct
3 Correct 65 ms 8532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5976 KB Output is correct
2 Correct 2 ms 5980 KB Output is correct
3 Correct 1 ms 5980 KB Output is correct
4 Correct 1 ms 5980 KB Output is correct
5 Correct 2 ms 5976 KB Output is correct
6 Correct 2 ms 5980 KB Output is correct
7 Correct 2 ms 5976 KB Output is correct
8 Correct 1 ms 5980 KB Output is correct
9 Correct 2 ms 5976 KB Output is correct
10 Correct 1 ms 5980 KB Output is correct
11 Correct 1 ms 5976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5976 KB Output is correct
2 Correct 2 ms 5980 KB Output is correct
3 Correct 1 ms 5980 KB Output is correct
4 Correct 1 ms 5980 KB Output is correct
5 Correct 2 ms 5976 KB Output is correct
6 Correct 2 ms 5980 KB Output is correct
7 Correct 2 ms 5976 KB Output is correct
8 Correct 1 ms 5980 KB Output is correct
9 Correct 2 ms 5976 KB Output is correct
10 Correct 1 ms 5980 KB Output is correct
11 Correct 1 ms 5976 KB Output is correct
12 Correct 2 ms 5976 KB Output is correct
13 Correct 2 ms 5976 KB Output is correct
14 Correct 2 ms 5976 KB Output is correct
15 Correct 2 ms 5976 KB Output is correct
16 Correct 2 ms 5976 KB Output is correct
17 Correct 2 ms 5976 KB Output is correct
18 Correct 2 ms 5976 KB Output is correct
19 Correct 2 ms 5976 KB Output is correct
20 Correct 2 ms 5976 KB Output is correct
21 Correct 2 ms 6232 KB Output is correct
22 Correct 2 ms 5976 KB Output is correct
23 Correct 2 ms 5980 KB Output is correct
24 Correct 2 ms 5976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5976 KB Output is correct
2 Correct 2 ms 5980 KB Output is correct
3 Correct 1 ms 5980 KB Output is correct
4 Correct 1 ms 5980 KB Output is correct
5 Correct 2 ms 5976 KB Output is correct
6 Correct 2 ms 5980 KB Output is correct
7 Correct 2 ms 5976 KB Output is correct
8 Correct 1 ms 5980 KB Output is correct
9 Correct 2 ms 5976 KB Output is correct
10 Correct 1 ms 5980 KB Output is correct
11 Correct 1 ms 5976 KB Output is correct
12 Correct 2 ms 5976 KB Output is correct
13 Correct 2 ms 5976 KB Output is correct
14 Correct 2 ms 5976 KB Output is correct
15 Correct 2 ms 5976 KB Output is correct
16 Correct 2 ms 5976 KB Output is correct
17 Correct 2 ms 5976 KB Output is correct
18 Correct 2 ms 5976 KB Output is correct
19 Correct 2 ms 5976 KB Output is correct
20 Correct 2 ms 5976 KB Output is correct
21 Correct 2 ms 6232 KB Output is correct
22 Correct 2 ms 5976 KB Output is correct
23 Correct 2 ms 5980 KB Output is correct
24 Correct 2 ms 5976 KB Output is correct
25 Correct 3 ms 5976 KB Output is correct
26 Correct 17 ms 6488 KB Output is correct
27 Correct 3 ms 6488 KB Output is correct
28 Correct 3 ms 6232 KB Output is correct
29 Correct 12 ms 6468 KB Output is correct
30 Correct 3 ms 6488 KB Output is correct
31 Correct 3 ms 6232 KB Output is correct
32 Correct 3 ms 6468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5976 KB Output is correct
2 Correct 2 ms 5976 KB Output is correct
3 Correct 2 ms 5980 KB Output is correct
4 Correct 1 ms 5980 KB Output is correct
5 Correct 1 ms 5980 KB Output is correct
6 Correct 2 ms 5976 KB Output is correct
7 Incorrect 1 ms 5976 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5976 KB Output is correct
2 Correct 2 ms 5976 KB Output is correct
3 Correct 2 ms 5980 KB Output is correct
4 Correct 1 ms 5980 KB Output is correct
5 Correct 1 ms 5980 KB Output is correct
6 Correct 2 ms 5976 KB Output is correct
7 Correct 2 ms 5980 KB Output is correct
8 Correct 2 ms 5976 KB Output is correct
9 Correct 1 ms 5980 KB Output is correct
10 Correct 2 ms 5976 KB Output is correct
11 Correct 1 ms 5980 KB Output is correct
12 Correct 1 ms 5976 KB Output is correct
13 Correct 2 ms 5976 KB Output is correct
14 Correct 2 ms 5976 KB Output is correct
15 Correct 2 ms 5976 KB Output is correct
16 Correct 2 ms 5976 KB Output is correct
17 Correct 2 ms 5976 KB Output is correct
18 Correct 2 ms 5976 KB Output is correct
19 Incorrect 1 ms 5976 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5976 KB Output is correct
2 Correct 2 ms 5976 KB Output is correct
3 Correct 2 ms 5980 KB Output is correct
4 Correct 1 ms 5980 KB Output is correct
5 Correct 1 ms 5980 KB Output is correct
6 Correct 2 ms 5976 KB Output is correct
7 Correct 2 ms 5980 KB Output is correct
8 Correct 2 ms 5976 KB Output is correct
9 Correct 1 ms 5980 KB Output is correct
10 Correct 2 ms 5976 KB Output is correct
11 Correct 1 ms 5980 KB Output is correct
12 Correct 1 ms 5976 KB Output is correct
13 Correct 2 ms 5976 KB Output is correct
14 Correct 2 ms 5976 KB Output is correct
15 Correct 2 ms 5976 KB Output is correct
16 Correct 2 ms 5976 KB Output is correct
17 Correct 2 ms 5976 KB Output is correct
18 Correct 2 ms 5976 KB Output is correct
19 Correct 2 ms 5976 KB Output is correct
20 Correct 2 ms 5976 KB Output is correct
21 Correct 2 ms 5976 KB Output is correct
22 Correct 2 ms 6232 KB Output is correct
23 Correct 2 ms 5976 KB Output is correct
24 Correct 2 ms 5980 KB Output is correct
25 Correct 2 ms 5976 KB Output is correct
26 Incorrect 1 ms 5976 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5976 KB Output is correct
2 Correct 2 ms 5976 KB Output is correct
3 Correct 2 ms 5980 KB Output is correct
4 Correct 1 ms 5980 KB Output is correct
5 Correct 1 ms 5980 KB Output is correct
6 Correct 2 ms 5976 KB Output is correct
7 Correct 2 ms 5980 KB Output is correct
8 Correct 2 ms 5976 KB Output is correct
9 Correct 1 ms 5980 KB Output is correct
10 Correct 2 ms 5976 KB Output is correct
11 Correct 1 ms 5980 KB Output is correct
12 Correct 1 ms 5976 KB Output is correct
13 Correct 2 ms 5976 KB Output is correct
14 Correct 2 ms 5976 KB Output is correct
15 Correct 2 ms 5976 KB Output is correct
16 Correct 2 ms 5976 KB Output is correct
17 Correct 2 ms 5976 KB Output is correct
18 Correct 2 ms 5976 KB Output is correct
19 Correct 2 ms 5976 KB Output is correct
20 Correct 2 ms 5976 KB Output is correct
21 Correct 2 ms 5976 KB Output is correct
22 Correct 2 ms 6232 KB Output is correct
23 Correct 2 ms 5976 KB Output is correct
24 Correct 2 ms 5980 KB Output is correct
25 Correct 2 ms 5976 KB Output is correct
26 Correct 3 ms 5976 KB Output is correct
27 Correct 17 ms 6488 KB Output is correct
28 Correct 3 ms 6488 KB Output is correct
29 Correct 3 ms 6232 KB Output is correct
30 Correct 12 ms 6468 KB Output is correct
31 Correct 3 ms 6488 KB Output is correct
32 Correct 3 ms 6232 KB Output is correct
33 Correct 3 ms 6468 KB Output is correct
34 Incorrect 1 ms 5976 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5976 KB Output is correct
2 Correct 2 ms 5976 KB Output is correct
3 Correct 2 ms 5980 KB Output is correct
4 Correct 1 ms 5980 KB Output is correct
5 Correct 1 ms 5980 KB Output is correct
6 Correct 2 ms 5976 KB Output is correct
7 Correct 2 ms 5980 KB Output is correct
8 Correct 2 ms 5976 KB Output is correct
9 Correct 1 ms 5980 KB Output is correct
10 Correct 2 ms 5976 KB Output is correct
11 Correct 1 ms 5980 KB Output is correct
12 Correct 1 ms 5976 KB Output is correct
13 Correct 2 ms 5976 KB Output is correct
14 Correct 2 ms 5976 KB Output is correct
15 Correct 2 ms 5976 KB Output is correct
16 Correct 2 ms 5976 KB Output is correct
17 Correct 2 ms 5976 KB Output is correct
18 Correct 2 ms 5976 KB Output is correct
19 Correct 2 ms 5976 KB Output is correct
20 Correct 2 ms 5976 KB Output is correct
21 Correct 2 ms 5976 KB Output is correct
22 Correct 2 ms 6232 KB Output is correct
23 Correct 2 ms 5976 KB Output is correct
24 Correct 2 ms 5980 KB Output is correct
25 Correct 2 ms 5976 KB Output is correct
26 Correct 3 ms 5976 KB Output is correct
27 Correct 17 ms 6488 KB Output is correct
28 Correct 3 ms 6488 KB Output is correct
29 Correct 3 ms 6232 KB Output is correct
30 Correct 12 ms 6468 KB Output is correct
31 Correct 3 ms 6488 KB Output is correct
32 Correct 3 ms 6232 KB Output is correct
33 Correct 3 ms 6468 KB Output is correct
34 Incorrect 1 ms 5976 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
35 Halted 0 ms 0 KB -