Submission #985297

# Submission time Handle Problem Language Result Execution time Memory
985297 2024-05-17T14:42:22 Z tvladm2009 Closing Time (IOI23_closing) C++17
29 / 100
1000 ms 28200 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
const int N = 2e5 + 7;
 
vector<pair<int, int>> g[N];
int ans = 0;
 
vector<ll> find_dist(int n, int x) {
    vector<ll> dist(n, -1);
    queue<int> q;
    q.push(x);
    dist[x] = 0;
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (auto v : g[u]) {
            if (dist[v.first] == -1) {
                dist[v.first] = dist[u] + v.second;
                q.push(v.first);
            }
        }
    }
    return dist;
}
 
int max_score(int n, int X, int Y, ll K, vector<int> U, vector<int> V, vector<int> W) {
    for (int i = 0; i < n; ++i) {
        g[i].clear();
    }
    ans = 0;
    for (int i = 0; i < n - 1; ++i) {
        g[U[i]].push_back(make_pair(V[i], W[i]));
        g[V[i]].push_back(make_pair(U[i], W[i]));
    }
    vector<ll> distX = find_dist(n, X);
    vector<ll> distY = find_dist(n, Y);
    vector<ll> one(n, 0), two(n, 0);
    for (int i = 0; i < n; ++i) {
        one[i] = min(distX[i], distY[i]);
        two[i] = max(distX[i], distY[i]);
    }
    {
        vector<ll> aux = one;
        sort(aux.begin(), aux.end());
        ll sum = 0;
        for (int i = 0; i < n; ++i) {
            if (sum + aux[i] <= K) {
                ans++;
                sum += aux[i];
            }
        }
        if (distX[Y] + 1 > 2 * K) {
            return ans;
        }
    }
    vector<bool> counted(n, 0);
    ll d = distX[Y], between = 0;
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        if (distX[i] + distY[i] == d) {
            between += one[i];
            cnt++;
            counted[i] = 1;
        }
    }
    ll sum_other_two = 0;
    vector<int> ord2(n);
    iota(ord2.begin(), ord2.end(), 0);
    sort(ord2.begin(), ord2.end(), [&](int x, int y) {
        return two[x] < two[y];
    });
    int ptr = 0;
 
    vector<int> ord1(n);
    iota(ord1.begin(), ord1.end(), 0);
    sort(ord1.begin(), ord1.end(), [&](int x, int y) {
        return one[x] < one[y];
    });
    auto get_sum_other_one = [&](int twos, int ones) {
        if (ones == 0) {
            return 0LL;
        }
        ll sum = 0;
        for (int i = 0; i < n; ++i) {
            if (counted[ord1[i]] == 0) {
                sum += one[ord1[i]];
                ones--;
                if (ones == 0) {
                    break;
                }
            }
        }
        return sum;
    };
 
    for (int twos = 0; twos <= n; ++twos) {
        if (twos != 0) {
            sum_other_two += two[ord2[ptr]];
            counted[ord2[ptr]] = 1;
            if (distX[ord2[ptr]] + distY[ord2[ptr]] == d) {
                between -= one[ord2[ptr]];
                cnt--;
            }
            ptr++;
        }
 
        for (int ones = 0; ones + twos + cnt <= n; ++ones) {
            if (sum_other_two + between + get_sum_other_one(twos, ones) <= K) {
                ans = max(ans, 2 * twos + cnt + ones);
            }
        }
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 93 ms 25004 KB Output is correct
2 Correct 97 ms 28200 KB Output is correct
3 Correct 57 ms 10124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4952 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 1 ms 4952 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4952 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 1 ms 4952 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 1 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 1 ms 4956 KB Output is correct
17 Correct 1 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 47 ms 5152 KB Output is correct
20 Correct 37 ms 4956 KB Output is correct
21 Correct 15 ms 4952 KB Output is correct
22 Correct 42 ms 5168 KB Output is correct
23 Correct 2 ms 5364 KB Output is correct
24 Correct 1 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4952 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 1 ms 4952 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 1 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 1 ms 4956 KB Output is correct
17 Correct 1 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 47 ms 5152 KB Output is correct
20 Correct 37 ms 4956 KB Output is correct
21 Correct 15 ms 4952 KB Output is correct
22 Correct 42 ms 5168 KB Output is correct
23 Correct 2 ms 5364 KB Output is correct
24 Correct 1 ms 4956 KB Output is correct
25 Correct 5 ms 4956 KB Output is correct
26 Execution timed out 1085 ms 5212 KB Time limit exceeded
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4952 KB Output is correct
7 Incorrect 1 ms 4952 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 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4952 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 1 ms 4952 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 1 ms 4956 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Incorrect 1 ms 4952 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 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4952 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 1 ms 4952 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 1 ms 4956 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 47 ms 5152 KB Output is correct
21 Correct 37 ms 4956 KB Output is correct
22 Correct 15 ms 4952 KB Output is correct
23 Correct 42 ms 5168 KB Output is correct
24 Correct 2 ms 5364 KB Output is correct
25 Correct 1 ms 4956 KB Output is correct
26 Incorrect 1 ms 4952 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 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4952 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 1 ms 4952 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 1 ms 4956 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 47 ms 5152 KB Output is correct
21 Correct 37 ms 4956 KB Output is correct
22 Correct 15 ms 4952 KB Output is correct
23 Correct 42 ms 5168 KB Output is correct
24 Correct 2 ms 5364 KB Output is correct
25 Correct 1 ms 4956 KB Output is correct
26 Correct 5 ms 4956 KB Output is correct
27 Execution timed out 1085 ms 5212 KB Time limit exceeded
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4952 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 1 ms 4952 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 1 ms 4956 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 47 ms 5152 KB Output is correct
21 Correct 37 ms 4956 KB Output is correct
22 Correct 15 ms 4952 KB Output is correct
23 Correct 42 ms 5168 KB Output is correct
24 Correct 2 ms 5364 KB Output is correct
25 Correct 1 ms 4956 KB Output is correct
26 Correct 5 ms 4956 KB Output is correct
27 Execution timed out 1085 ms 5212 KB Time limit exceeded
28 Halted 0 ms 0 KB -