Submission #848656

# Submission time Handle Problem Language Result Execution time Memory
848656 2023-09-13T07:53:57 Z eltu0815 Closing Time (IOI23_closing) C++17
21 / 100
1000 ms 25820 KB
#include "closing.h"

#include <bits/stdc++.h>
#define MAX 200005
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

int visited[MAX];
vector<pii> graph[MAX];
ll dist1[MAX], dist2[MAX];

void dfs1(int node) {
    visited[node] = 1;
    for(auto [v, w] : graph[node]) {
        if(visited[v]) continue;
        dist1[v] = dist1[node] + w;
        dfs1(v);
    }
}

void dfs2(int node) {
    visited[node] = 1;
    for(auto [v, w] : graph[node]) {
        if(visited[v]) continue;
        dist2[v] = dist2[node] + w;
        dfs2(v);
    }
}

ll c[MAX];

int max_score(int N, int X, int Y, long long K, vector<int> U, vector<int> V, vector<int> W)
{
    for(int i = 0; i < N; ++i) graph[i].clear();
    for(int i = 0; i < N - 1; ++i) {
        graph[U[i]].push_back({V[i], W[i]});
        graph[V[i]].push_back({U[i], W[i]});
    }
    
    for(int i = 0; i < N; ++i) visited[i] = dist1[i] = 0;
    dfs1(X);
    
    for(int i = 0; i < N; ++i) visited[i] = dist2[i] = 0;
    dfs2(Y);
    
    int ans = 0;
    for(int p = X; p < N; ++p) for(int q = 0; q <= Y; ++q) {
        for(int i = 0; i < N; ++i) c[i] = 0;
        for(int i = X; i <= p; ++i) c[i] = max(c[i], dist1[i]);
        for(int i = q; i <= Y; ++i) c[i] = max(c[i], dist2[i]);
        
        ll sum = 0;
        int cur = p - X + Y - q + 2;
        for(int i = 0; i < N; ++i) sum += c[i];
        
        if(sum > K) continue;
        
        int a = X, b = Y;
        while(true) {
            if(a == 0 && b == N - 1) break;
            if(a == 0) {
                ll val = max(0ll, dist2[b + 1] - c[b + 1]);
                if(sum + val <= K) sum += val, ++cur, ++b;
                else break;
                continue;
            }
            if(b == N - 1) {
                ll val = max(0ll, dist1[a - 1] - c[a - 1]);
                if(sum + val <= K) sum += val, ++cur, --a;
                else break;
                continue;
            }
            ll val1 = max(0ll, dist1[a - 1] - c[a - 1]);
            ll val2 = max(0ll, dist2[b + 1] - c[b + 1]);
            if(val1 <= val2) {
                if(sum + val1 <= K) sum += val1, ++cur, --a;
                else break;
            }
            else {
                if(sum + val2 <= K) sum += val2, ++cur, ++b;
                else break;
            }
        }
        
        ans = max(ans, cur);
    }
    return ans;
}

/*
2
7 0 2 10
0 1 2
0 3 3
1 2 4
2 4 2
2 5 5
5 6 3
4 0 3 20
0 1 18
1 2 1
2 3 19
*/
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 9560 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1046 ms 25820 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9560 KB Output is correct
2 Correct 2 ms 9560 KB Output is correct
3 Correct 2 ms 9560 KB Output is correct
4 Correct 2 ms 9560 KB Output is correct
5 Correct 2 ms 9560 KB Output is correct
6 Correct 2 ms 9560 KB Output is correct
7 Correct 2 ms 9560 KB Output is correct
8 Correct 2 ms 9560 KB Output is correct
9 Correct 2 ms 9560 KB Output is correct
10 Correct 2 ms 9816 KB Output is correct
11 Correct 2 ms 9564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9560 KB Output is correct
2 Correct 2 ms 9560 KB Output is correct
3 Correct 2 ms 9560 KB Output is correct
4 Correct 2 ms 9560 KB Output is correct
5 Correct 2 ms 9560 KB Output is correct
6 Correct 2 ms 9560 KB Output is correct
7 Correct 2 ms 9560 KB Output is correct
8 Correct 2 ms 9560 KB Output is correct
9 Correct 2 ms 9560 KB Output is correct
10 Correct 2 ms 9816 KB Output is correct
11 Correct 2 ms 9564 KB Output is correct
12 Correct 2 ms 9564 KB Output is correct
13 Correct 3 ms 9560 KB Output is correct
14 Correct 3 ms 9560 KB Output is correct
15 Correct 2 ms 9560 KB Output is correct
16 Correct 3 ms 9560 KB Output is correct
17 Correct 3 ms 9564 KB Output is correct
18 Correct 2 ms 9560 KB Output is correct
19 Correct 55 ms 9560 KB Output is correct
20 Correct 6 ms 9564 KB Output is correct
21 Correct 127 ms 9560 KB Output is correct
22 Correct 57 ms 9692 KB Output is correct
23 Correct 140 ms 9560 KB Output is correct
24 Correct 143 ms 9692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9560 KB Output is correct
2 Correct 2 ms 9560 KB Output is correct
3 Correct 2 ms 9560 KB Output is correct
4 Correct 2 ms 9560 KB Output is correct
5 Correct 2 ms 9560 KB Output is correct
6 Correct 2 ms 9560 KB Output is correct
7 Correct 2 ms 9560 KB Output is correct
8 Correct 2 ms 9560 KB Output is correct
9 Correct 2 ms 9560 KB Output is correct
10 Correct 2 ms 9816 KB Output is correct
11 Correct 2 ms 9564 KB Output is correct
12 Correct 2 ms 9564 KB Output is correct
13 Correct 3 ms 9560 KB Output is correct
14 Correct 3 ms 9560 KB Output is correct
15 Correct 2 ms 9560 KB Output is correct
16 Correct 3 ms 9560 KB Output is correct
17 Correct 3 ms 9564 KB Output is correct
18 Correct 2 ms 9560 KB Output is correct
19 Correct 55 ms 9560 KB Output is correct
20 Correct 6 ms 9564 KB Output is correct
21 Correct 127 ms 9560 KB Output is correct
22 Correct 57 ms 9692 KB Output is correct
23 Correct 140 ms 9560 KB Output is correct
24 Correct 143 ms 9692 KB Output is correct
25 Correct 10 ms 9560 KB Output is correct
26 Execution timed out 1051 ms 9816 KB Time limit exceeded
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 9560 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 9560 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 9560 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 9560 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 9560 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -