Submission #1056710

# Submission time Handle Problem Language Result Execution time Memory
1056710 2024-08-13T10:41:52 Z Ignut Closing Time (IOI23_closing) C++17
9 / 100
1000 ms 26564 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];
            }

            int L = min(pos[X], l);
            int R = max(pos[Y], r);

            for (int i = 0; i < L; i ++) {
                ll sx = sumX[L] - sumX[i];
                int cx = L - i;
                if (sum + sx <= K) res = max(res, ans + cx);

                int lo = R + 1, hi = N - 1;
                while (lo < hi) {
                    int mid = lo + (hi - lo + 1) / 2;
                    ll sy = sumY[mid + 1] - sumY[R + 1];
                    if (sum + sx + sy <= K)
                        lo = mid;
                    else
                        hi = mid - 1;
                }
                
                if (lo >= N) continue;
                
                ll sy = sumY[lo + 1] - sumY[R + 1];
                int cy = lo - R;
                if (sum + sx + sy <= K) res = max(res, ans + cx + cy);
            }

            // vector<ll> ds;
            // for (int i = 0; i < L; i ++) ds.push_back(dx[order[i]]);
            // for (int i = 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:158:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  158 |     for (int i = 0; i < ds.size(); i ++) {
      |                     ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1010 ms 26564 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8796 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 8796 KB Output is correct
5 Correct 1 ms 8796 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 1 ms 8796 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 1 ms 8796 KB Output is correct
11 Correct 2 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8796 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 8796 KB Output is correct
5 Correct 1 ms 8796 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 1 ms 8796 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 1 ms 8796 KB Output is correct
11 Correct 2 ms 8796 KB Output is correct
12 Correct 2 ms 8796 KB Output is correct
13 Correct 1 ms 8796 KB Output is correct
14 Correct 1 ms 8796 KB Output is correct
15 Correct 2 ms 8796 KB Output is correct
16 Correct 1 ms 8796 KB Output is correct
17 Correct 1 ms 8792 KB Output is correct
18 Incorrect 1 ms 8792 KB 9th lines differ - on the 1st token, expected: '26', found: '23'
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8796 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 8796 KB Output is correct
5 Correct 1 ms 8796 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 1 ms 8796 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 1 ms 8796 KB Output is correct
11 Correct 2 ms 8796 KB Output is correct
12 Correct 2 ms 8796 KB Output is correct
13 Correct 1 ms 8796 KB Output is correct
14 Correct 1 ms 8796 KB Output is correct
15 Correct 2 ms 8796 KB Output is correct
16 Correct 1 ms 8796 KB Output is correct
17 Correct 1 ms 8792 KB Output is correct
18 Incorrect 1 ms 8792 KB 9th lines differ - on the 1st token, expected: '26', found: '23'
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 1 ms 8796 KB Output is correct
3 Correct 1 ms 8792 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 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 2 ms 8796 KB Output is correct
2 Correct 1 ms 8796 KB Output is correct
3 Correct 1 ms 8792 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 2 ms 8796 KB Output is correct
8 Correct 1 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 8796 KB Output is correct
11 Correct 1 ms 8796 KB Output is correct
12 Correct 2 ms 8796 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
14 Correct 1 ms 8796 KB Output is correct
15 Correct 1 ms 8796 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 1 ms 8796 KB Output is correct
18 Correct 1 ms 8792 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 2 ms 8796 KB Output is correct
2 Correct 1 ms 8796 KB Output is correct
3 Correct 1 ms 8792 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 2 ms 8796 KB Output is correct
8 Correct 1 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 8796 KB Output is correct
11 Correct 1 ms 8796 KB Output is correct
12 Correct 2 ms 8796 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
14 Correct 1 ms 8796 KB Output is correct
15 Correct 1 ms 8796 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 1 ms 8796 KB Output is correct
18 Correct 1 ms 8792 KB Output is correct
19 Incorrect 1 ms 8792 KB 9th lines differ - on the 1st token, expected: '26', found: '23'
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 1 ms 8796 KB Output is correct
3 Correct 1 ms 8792 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 2 ms 8796 KB Output is correct
8 Correct 1 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 8796 KB Output is correct
11 Correct 1 ms 8796 KB Output is correct
12 Correct 2 ms 8796 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
14 Correct 1 ms 8796 KB Output is correct
15 Correct 1 ms 8796 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 1 ms 8796 KB Output is correct
18 Correct 1 ms 8792 KB Output is correct
19 Incorrect 1 ms 8792 KB 9th lines differ - on the 1st token, expected: '26', found: '23'
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 1 ms 8796 KB Output is correct
3 Correct 1 ms 8792 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 2 ms 8796 KB Output is correct
8 Correct 1 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 8796 KB Output is correct
11 Correct 1 ms 8796 KB Output is correct
12 Correct 2 ms 8796 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
14 Correct 1 ms 8796 KB Output is correct
15 Correct 1 ms 8796 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 1 ms 8796 KB Output is correct
18 Correct 1 ms 8792 KB Output is correct
19 Incorrect 1 ms 8792 KB 9th lines differ - on the 1st token, expected: '26', found: '23'
20 Halted 0 ms 0 KB -