Submission #870635

# Submission time Handle Problem Language Result Execution time Memory
870635 2023-11-08T15:46:39 Z ThommyDB Closing Time (IOI23_closing) C++17
0 / 100
73 ms 24392 KB
#include<bits/stdc++.h>

using namespace std;

vector<vector<pair<int, long long>>> adj;
vector<int> W;

int N, Y, X;

long long DP(int curr, int prv, int K, int time, long long ans, int connectedCities, int connectedXY, bool stop){
    long long val = 0;
    if(stop){
        val += (connectedCities*connectedXY)-connectedXY;
        connectedCities=1;
    }
    if(curr==X || curr==Y){
        connectedXY++;
    }
    if(time+W[curr]>K){
        val += connectedCities*connectedXY;
        connectedCities=1;
        return val;
    }
    if(adj[curr][0].first==prv){
        if(adj[curr].size()!=1){
            val = DP(adj[curr][1].first, curr, K, time+W[curr], ans, connectedCities+1, connectedXY, false);
            val = max(DP(adj[curr][1].first, curr, K, time, ans, connectedCities, 0, true), val);
        }
    }
    else{
        val= DP(adj[curr][0].first, curr, K, time+W[curr], ans, connectedCities+1, connectedXY, false);
        val = max(DP(adj[curr][0].first, curr, K, time, ans, connectedCities, 0, true), val);
    }
    if(adj[curr].size()==1){
        val += (connectedCities*connectedXY)-connectedXY;
        connectedCities=1;
    }
    return val;
}

int max_score(int n, int x, int y, long long K, vector<int> U, vector<int> V, vector<int> w){
    N=n;
    Y=y;
    X=x;
    W=w;
    adj.assign(N, vector<pair<int, long long>>(0));
    for(int i = 0; i < N-1; i++){
        adj[U[i]].push_back({V[i], W[i]});
        adj[V[i]].push_back({U[i], W[i]});
    }
    int start = -1;
    for(int i = 0; i < N; i++){
        if(adj[i].size()==1){
            start=i;
            break;
        }
    }
    long long ans = DP(start, -1, K, 0, 0, 1, 0, false);
    return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '8'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 73 ms 24392 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 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '8'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '8'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '8'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '8'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '8'
2 Halted 0 ms 0 KB -