Submission #864069

# Submission time Handle Problem Language Result Execution time Memory
864069 2023-10-21T20:15:12 Z VMaksimoski008 Closing Time (IOI23_closing) C++17
0 / 100
1000 ms 23008 KB
#include <bits/stdc++.h>

#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define uniq(x) x.erase(unique(all(x)), x.end())
#define rall(x) x.rbegin(), x.rend()
//#define int long long

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Node = array<ll, 3>;

const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
const double eps = 1e-9;

void setIO() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

int n;
vector<vector<pii> > graph;
vector<int> dist1, dist2;

void dfs(int u, int p, int a, int d) {
    if(a == 1) dist1[u] = d;
    else dist2[u] = d;

    for(pii &next : graph[u]) {
        int v = next.first;
        int w = next.second;
        if(v == p) continue;
        dfs(v, u, a, d + w);
    }
}

int max_score(int N, int X, int Y, ll K, vector<int> U, vector<int> V, vector<int> W) {
    n = N;
    graph.clear();
    graph.resize(n);
    dist1.clear();
    dist1.resize(n);
    dist2.clear();
    dist2.resize(n);

    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]});
    }

    if(X > Y) swap(X, Y);
    dfs(X, 0, 1, 0);
    dfs(Y, 0, 2, 0);

    int ans = 0;

    for(int i=0; i<=X; i++) {
        for(int j=Y; j<n; j++) {
            for(int k=X+1; k<Y; k++) {
                for(int l=k; l<Y; l++) {
                    int ans2 = (j - i + 1) - (l - k + 1);
                    ll total = 0;

                    for(int x=i; x<=j; x++) {
                        if(x < k) total += min(dist1[x], dist2[x]);
                        if(x > l) total += min(dist1[x], dist2[x]);
                    } 

                    if(total <= K) ans = max(ans, ans2);
                }
            }
        }
    }

    for(int i=0; i<=X; i++) {
        for(int j=Y; j<n; j++) {
            for(int k=i; k<=j; k++) {
                for(int l=k; l<=j; l++) {
                    int ans2 = (j - i + 1) + (l - k + 1);
                    ll total = 0;

                    for(int x=i; x<=j; x++) {
                        if(x >= k && x <= l) total += max(dist1[x], dist2[x]);
                        else total += min(dist1[x], dist2[x]);
                    } 

                    if(total <= K) ans = max(ans, ans2);
                }
            }
        }
    }

    return ans;
}

// int32_t main() {
//     setIO();

//     

//     return 0;
// }
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1016 ms 23008 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 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 348 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 348 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 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
3 Halted 0 ms 0 KB -