Submission #1056656

# Submission time Handle Problem Language Result Execution time Memory
1056656 2024-08-13T10:29:26 Z Ignut Closing Time (IOI23_closing) C++17
21 / 100
1000 ms 27624 KB
/* Ignut
started: 13.08.2024
now: 13.08.2024
████████████████████████████████████████████████████████████████████
████████████████████████████████    ████████████████████████████████
██████████████████████████████        ██████████████████████████████
██████      ██████████████████        ██████████████████      ██████
██████          ██████████████        ██████████████          ██████
██████      ██    ████████████        ████████████    ██      ██████
██████      ████    ██████████        ██████████    ████      ██████
██████      ████      ██████████    ██████████      ████      ██████
██████      ████      ██████████    ██████████    ██████      ██████
██████      ██████    ██████████    ██████████    ██████      ██████
██████      ██████    ████████        ████████    ██████      ██████
██████      ██████      ██████        ██████      ██████      ██████
██████      ████        ████            ████        ████      ██████
██████            ██████████    ████    ██████████            ██████
██████      ██      ██████    ████████    ██████      ██      ██████
██████      ██████            ████████            ██████      ██████
██████                    ██            ██                    ██████
██████████████████████      ████    ████      ██████████████████████
████████████████████████      ██    ██      ████████████████████████
██████████████████████████                ██████████████████████████
██████████████████████████████        ██████████████████████████████
████████████████████████████████████████████████████████████████████
*/
 
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
 
const int MAXN = 2e5 + 123;
 
vector<pair<int, int>> tree[MAXN];
    
vector<int> order;
int pos[MAXN];
 
void dfs(int v, int par) {
    order.push_back(v);
    for (auto [to, w] : tree[v])
        if (to != par)
            dfs(to, v);
}
 
ll dx[MAXN], dy[MAXN];
 
void dfs2(int v, int par, ll d, bool f) {
    if (f) dx[v] = d;
    else dy[v] = d;
    for (auto [to, w] : tree[v])
        if (to != par)
            dfs2(to, v, d + w, f);
}
 
int max_score(int N, int X, int Y, ll K, vector<int> U, vector<int> V, vector<int> W) {
    order.clear();
    for (int i = 0; i < N; i ++)
        tree[i].clear();
    for (int i = 0; i < N - 1; i ++) {
        tree[U[i]].push_back({V[i], W[i]});
        tree[V[i]].push_back({U[i], W[i]});
    }
    int start = 0;
    for (int i = 0; i < N; i ++) {
        if (tree[i].size() == 1) {
            start = i; break;
        }
    }
    dfs(start, -1);
    for (int i = 0; i < N; i ++) pos[order[i]] = i;
 
    dfs2(X, -1, 0, true);
    dfs2(Y, -1, 0, false);
 
    if (pos[X] > pos[Y]) {
        swap(X, Y);
        for (int i = 0; i < N; i ++) swap(dx[i], dy[i]);
    }
 
    ll sumX[N + 1] = {};
    ll sumY[N + 1] = {};
    ll sum2[N + 1] = {};
    for (int i = 0; i < N; i ++) {
        sumX[i + 1] = sumX[i] + dx[order[i]];
        sumY[i + 1] = sumY[i] + dy[order[i]];
        sum2[i + 1] = sum2[i] + max(dx[order[i]], dy[order[i]]);
    }

    int res = 0;
 
    for (int l = 0; l < N; l ++) {
        for (int r = l; r < N; r ++) {
            ll sum = 0;
            int ans = (r - l + 1) * 2;
            sum = sum2[r + 1] - sum2[l];
            if (pos[X] < l) {
                ans += l - pos[X];
                sum += sumX[l] - sumX[pos[X]];
            }
            if (pos[Y] > r) {
                ans += pos[Y] - r;
                sum += sumY[pos[Y] + 1] - sumY[r + 1];
            }
            // for (int i = pos[Y]; i > r; i --) sum += dy[order[i]];
            vector<ll> ds;
            for (int i = 0; i < min(pos[X], l); i ++) ds.push_back(dx[order[i]]);
            for (int i = max(pos[Y], r) + 1; i < N; i ++) ds.push_back(dy[order[i]]);
            sort(ds.begin(), ds.end());
            for (int i = 0; i < ds.size(); i ++) {
                if (sum + ds[i] <= K) {
                    sum += ds[i];
                    ans ++;
                }
            }
            if (sum <= K)
                res = max(res, ans);
        }
    }
 
    // no overlap
    vector<ll> ds;
    for (int i = 0; i < N; i ++) {
        ds.push_back(dx[i]);
        ds.push_back(dy[i]);
    }
    sort(ds.begin(), ds.end());
    ll sum = 0;
    int ans = 0;
    for (int i = 0; i < ds.size(); i ++) {
        if (sum + ds[i] <= K) {
            sum += ds[i];
            ans ++;
        }
    }
    res = max(res, ans);
 
    return res;
}

Compilation message

closing.cpp: In function 'int max_score(int, int, int, ll, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:111:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |             for (int i = 0; i < ds.size(); i ++) {
      |                             ~~^~~~~~~~~~~
closing.cpp:131:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  131 |     for (int i = 0; i < ds.size(); i ++) {
      |                     ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1059 ms 27624 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8792 KB Output is correct
2 Correct 1 ms 8796 KB Output is correct
3 Correct 1 ms 8884 KB Output is correct
4 Correct 1 ms 8796 KB Output is correct
5 Correct 1 ms 8796 KB Output is correct
6 Correct 1 ms 8796 KB Output is correct
7 Correct 1 ms 8820 KB Output is correct
8 Correct 1 ms 8796 KB Output is correct
9 Correct 1 ms 8796 KB Output is correct
10 Correct 1 ms 8796 KB Output is correct
11 Correct 1 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8792 KB Output is correct
2 Correct 1 ms 8796 KB Output is correct
3 Correct 1 ms 8884 KB Output is correct
4 Correct 1 ms 8796 KB Output is correct
5 Correct 1 ms 8796 KB Output is correct
6 Correct 1 ms 8796 KB Output is correct
7 Correct 1 ms 8820 KB Output is correct
8 Correct 1 ms 8796 KB Output is correct
9 Correct 1 ms 8796 KB Output is correct
10 Correct 1 ms 8796 KB Output is correct
11 Correct 1 ms 8796 KB Output is correct
12 Correct 3 ms 8796 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
14 Correct 2 ms 8796 KB Output is correct
15 Correct 3 ms 8796 KB Output is correct
16 Correct 2 ms 8792 KB Output is correct
17 Correct 2 ms 8796 KB Output is correct
18 Correct 1 ms 8796 KB Output is correct
19 Correct 312 ms 8924 KB Output is correct
20 Correct 132 ms 8920 KB Output is correct
21 Correct 142 ms 8912 KB Output is correct
22 Correct 132 ms 8796 KB Output is correct
23 Correct 2 ms 8796 KB Output is correct
24 Correct 2 ms 8876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8792 KB Output is correct
2 Correct 1 ms 8796 KB Output is correct
3 Correct 1 ms 8884 KB Output is correct
4 Correct 1 ms 8796 KB Output is correct
5 Correct 1 ms 8796 KB Output is correct
6 Correct 1 ms 8796 KB Output is correct
7 Correct 1 ms 8820 KB Output is correct
8 Correct 1 ms 8796 KB Output is correct
9 Correct 1 ms 8796 KB Output is correct
10 Correct 1 ms 8796 KB Output is correct
11 Correct 1 ms 8796 KB Output is correct
12 Correct 3 ms 8796 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
14 Correct 2 ms 8796 KB Output is correct
15 Correct 3 ms 8796 KB Output is correct
16 Correct 2 ms 8792 KB Output is correct
17 Correct 2 ms 8796 KB Output is correct
18 Correct 1 ms 8796 KB Output is correct
19 Correct 312 ms 8924 KB Output is correct
20 Correct 132 ms 8920 KB Output is correct
21 Correct 142 ms 8912 KB Output is correct
22 Correct 132 ms 8796 KB Output is correct
23 Correct 2 ms 8796 KB Output is correct
24 Correct 2 ms 8876 KB Output is correct
25 Correct 17 ms 8796 KB Output is correct
26 Execution timed out 1097 ms 9052 KB Time limit exceeded
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8792 KB Output is correct
2 Correct 1 ms 8792 KB Output is correct
3 Correct 1 ms 8796 KB Output is correct
4 Correct 1 ms 8884 KB Output is correct
5 Correct 1 ms 8796 KB Output is correct
6 Correct 1 ms 8796 KB Output is correct
7 Incorrect 1 ms 8796 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 1 ms 8792 KB Output is correct
2 Correct 1 ms 8792 KB Output is correct
3 Correct 1 ms 8796 KB Output is correct
4 Correct 1 ms 8884 KB Output is correct
5 Correct 1 ms 8796 KB Output is correct
6 Correct 1 ms 8796 KB Output is correct
7 Correct 1 ms 8796 KB Output is correct
8 Correct 1 ms 8820 KB Output is correct
9 Correct 1 ms 8796 KB Output is correct
10 Correct 1 ms 8796 KB Output is correct
11 Correct 1 ms 8796 KB Output is correct
12 Correct 1 ms 8796 KB Output is correct
13 Correct 3 ms 8796 KB Output is correct
14 Correct 2 ms 8796 KB Output is correct
15 Correct 2 ms 8796 KB Output is correct
16 Correct 3 ms 8796 KB Output is correct
17 Correct 2 ms 8792 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Incorrect 1 ms 8796 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 1 ms 8792 KB Output is correct
2 Correct 1 ms 8792 KB Output is correct
3 Correct 1 ms 8796 KB Output is correct
4 Correct 1 ms 8884 KB Output is correct
5 Correct 1 ms 8796 KB Output is correct
6 Correct 1 ms 8796 KB Output is correct
7 Correct 1 ms 8796 KB Output is correct
8 Correct 1 ms 8820 KB Output is correct
9 Correct 1 ms 8796 KB Output is correct
10 Correct 1 ms 8796 KB Output is correct
11 Correct 1 ms 8796 KB Output is correct
12 Correct 1 ms 8796 KB Output is correct
13 Correct 3 ms 8796 KB Output is correct
14 Correct 2 ms 8796 KB Output is correct
15 Correct 2 ms 8796 KB Output is correct
16 Correct 3 ms 8796 KB Output is correct
17 Correct 2 ms 8792 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 1 ms 8796 KB Output is correct
20 Correct 312 ms 8924 KB Output is correct
21 Correct 132 ms 8920 KB Output is correct
22 Correct 142 ms 8912 KB Output is correct
23 Correct 132 ms 8796 KB Output is correct
24 Correct 2 ms 8796 KB Output is correct
25 Correct 2 ms 8876 KB Output is correct
26 Incorrect 1 ms 8796 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 1 ms 8792 KB Output is correct
2 Correct 1 ms 8792 KB Output is correct
3 Correct 1 ms 8796 KB Output is correct
4 Correct 1 ms 8884 KB Output is correct
5 Correct 1 ms 8796 KB Output is correct
6 Correct 1 ms 8796 KB Output is correct
7 Correct 1 ms 8796 KB Output is correct
8 Correct 1 ms 8820 KB Output is correct
9 Correct 1 ms 8796 KB Output is correct
10 Correct 1 ms 8796 KB Output is correct
11 Correct 1 ms 8796 KB Output is correct
12 Correct 1 ms 8796 KB Output is correct
13 Correct 3 ms 8796 KB Output is correct
14 Correct 2 ms 8796 KB Output is correct
15 Correct 2 ms 8796 KB Output is correct
16 Correct 3 ms 8796 KB Output is correct
17 Correct 2 ms 8792 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 1 ms 8796 KB Output is correct
20 Correct 312 ms 8924 KB Output is correct
21 Correct 132 ms 8920 KB Output is correct
22 Correct 142 ms 8912 KB Output is correct
23 Correct 132 ms 8796 KB Output is correct
24 Correct 2 ms 8796 KB Output is correct
25 Correct 2 ms 8876 KB Output is correct
26 Correct 17 ms 8796 KB Output is correct
27 Execution timed out 1097 ms 9052 KB Time limit exceeded
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8792 KB Output is correct
2 Correct 1 ms 8792 KB Output is correct
3 Correct 1 ms 8796 KB Output is correct
4 Correct 1 ms 8884 KB Output is correct
5 Correct 1 ms 8796 KB Output is correct
6 Correct 1 ms 8796 KB Output is correct
7 Correct 1 ms 8796 KB Output is correct
8 Correct 1 ms 8820 KB Output is correct
9 Correct 1 ms 8796 KB Output is correct
10 Correct 1 ms 8796 KB Output is correct
11 Correct 1 ms 8796 KB Output is correct
12 Correct 1 ms 8796 KB Output is correct
13 Correct 3 ms 8796 KB Output is correct
14 Correct 2 ms 8796 KB Output is correct
15 Correct 2 ms 8796 KB Output is correct
16 Correct 3 ms 8796 KB Output is correct
17 Correct 2 ms 8792 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 1 ms 8796 KB Output is correct
20 Correct 312 ms 8924 KB Output is correct
21 Correct 132 ms 8920 KB Output is correct
22 Correct 142 ms 8912 KB Output is correct
23 Correct 132 ms 8796 KB Output is correct
24 Correct 2 ms 8796 KB Output is correct
25 Correct 2 ms 8876 KB Output is correct
26 Correct 17 ms 8796 KB Output is correct
27 Execution timed out 1097 ms 9052 KB Time limit exceeded
28 Halted 0 ms 0 KB -