Submission #966376

# Submission time Handle Problem Language Result Execution time Memory
966376 2024-04-19T18:54:11 Z VMaksimoski008 Closing Time (IOI23_closing) C++17
9 / 100
1000 ms 30144 KB
#include "closing.h"
#include <bits/stdc++.h>
using namespace std;

int n, x, y, k;
vector<vector<pair<int, int> >> graph;
const int maxn = 2e5 + 5;
using ll = long long;
ll dist[2][maxn];

void dfs(int u, int p, int t) {
    for(auto &[v, w] : graph[u]) {
        if(v == p) continue;
        dist[t][v] = dist[t][u] + w;
        dfs(v, u, t);
    }
}

int max_score(int N, int X, int Y, long long K, std::vector<int> U, std::vector<int> V, std::vector<int> W) {
    n = N;
    x = X;
    y = Y;
    k = K;
    graph.resize(n);

    bool line = 1;
    for(int i=0; i<n-1; i++) {
        if(abs(U[i] - V[i]) != 1) line = 0;
        graph[U[i]].push_back({ V[i], W[i] });
        graph[V[i]].push_back({ U[i], W[i] });
    }

    if(line) {
        int ans = 0;
        dfs(x, x, 0);
        dfs(y, y, 1);

        for(int a=x; a<n; a++) {
            for(int b=x; b>=0; b--) {
                for(int c=y; c<n; c++) {
                    for(int d=y; d>=0; d--) {
                        ll total = 0;
                        for(int i=0; i<n; i++) {
                            ll curr = 0;
                            if(b <= i && i <= a) curr = max(curr, dist[0][i]);
                            if(d <= i && i <= c) curr = max(curr, dist[1][i]);
                            total += curr;
                        }

                        if(total <= k) ans = max(ans, a - b + c - d);
                    }
                }
            }
        }

        return ans + 2;
    }

    int ans = 0;
    ll total = 0;
    dfs(x, 0, 0);
    dfs(y, 0, 1);
    priority_queue<ll, vector<ll>, greater<ll> > pq;

    for(int i=0; i<2; i++)
        for(int j=0; j<n; j++) pq.push(dist[i][j]);

    while(!pq.empty() && pq.top() + total <= k) {
        ans++;
        total += pq.top();
        pq.pop();
    }

    return ans;
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 97 ms 30144 KB 1st lines differ - on the 1st token, expected: '451', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 44 ms 424 KB Output is correct
7 Correct 34 ms 344 KB Output is correct
8 Correct 12 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 44 ms 424 KB Output is correct
7 Correct 34 ms 344 KB Output is correct
8 Correct 12 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 158 ms 432 KB Output is correct
13 Correct 96 ms 348 KB Output is correct
14 Correct 297 ms 436 KB Output is correct
15 Correct 144 ms 436 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Execution timed out 1098 ms 348 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 44 ms 424 KB Output is correct
7 Correct 34 ms 344 KB Output is correct
8 Correct 12 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 158 ms 432 KB Output is correct
13 Correct 96 ms 348 KB Output is correct
14 Correct 297 ms 436 KB Output is correct
15 Correct 144 ms 436 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Execution timed out 1098 ms 348 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -