답안 #991740

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
991740 2024-06-03T04:23:10 Z stdfloat 봉쇄 시간 (IOI23_closing) C++17
0 / 100
1000 ms 25288 KB
#include <bits/stdc++.h>
#include "closing.h"
using namespace std;

#define ff  first
#define ss  second
#define pii pair<int, int>

using ll = long long;

int max_score(int n, int X, int Y, long long K, vector<int> U, vector<int> V, vector<int> W) {
    vector<pii> E[n];
    for (int i = 0; i < n - 1; i++) {
        E[U[i]].push_back({V[i], W[i]});
        E[V[i]].push_back({U[i], W[i]});
    }

    auto f = [&](int st) -> vector<ll> {
        queue<int> q;
        vector<ll> dis(n, -1);
        q.push(st); dis[st] = 0;
        while (!q.empty()) {
            auto x = q.front(); q.pop();

            for (auto [i, w] : E[x]) {
                if (dis[i] == -1) {
                    dis[i] = dis[x] + w;
                    q.push(i);
                }
            }
        }

        return dis;
    };

    vector<ll> disx = f(X), disy = f(Y);

    vector<pii> v;
    for (int i = 0; i < n; i++) {
        if ((int)E[i].size() == 1) {
            v.push_back({i, 0});
            
            queue<int> q;
            vector<bool> vis(n);
            q.push(i); vis[i] = true;
            while (!q.empty()) {
                auto x = q.front(); q.pop();


                for (auto [j, w] : E[x]) {
                    if (!vis[j]) {
                        q.push(j);
                        vis[j] = true;
                        v.push_back({j, w});
                    }
                }
            }
        
            break;
        }
    }

    for (auto [i, w] : v) {
        if (i == X || i == Y) {
            if (i == Y) swap(X, Y);
            break;
        }
    }

    int a = -1, b = -1;
    for (int i = 0; i < (int)v.size(); i++) {
        if (v[i].ff == X) a = i;
        else if (v[i].ff == Y) b = i;
    }

    vector<int> u;
    for (int k = 0; k < n; k++) {
        u.push_back(min(disx[v[k].ff], disy[v[k].ff]));
    }

    sort(u.begin(), u.end());

    ll sm = 0;
    int cnt = 0;
    for (auto i : u) {
        if (sm + i <= K) {
            sm += i;
            cnt++;
        }
        else break;
    }

    int mx = cnt;
    for (int i = 0; i < n; i++) {
        for (int j = i; j < n; j++) {
            vector<ll> c(n, -1);
            for (auto x : {a, b}) {
                for (auto y : {i, j}) {
                    ll sm = 0;
                    c[x] = max(c[x], 0LL);
                    if (y <= x) {
                        for (int k = x - 1; k >= y; k--)
                            c[k] = max(c[k], sm += v[k + 1].ss);
                    }
                    else {
                        for (int k = x + 1; k <= y; k++)
                            c[k] = max(c[k], sm += v[k].ss);
                    }
                }
            }

            ll sm = accumulate(c.begin(), c.end(), 0LL);

            if (sm > K) break;

            vector<int> u;
            for (int k = 0; k < n; k++) {
                if (c[k] == -1) u.push_back(min(disx[v[k].ff], disy[v[k].ff]));
            }

            sort(u.begin(), u.end());
            
            int cnt = (j - i + 1) << 1;
            for (auto i : u) {
                if (sm + i <= K) {
                    sm += i;
                    cnt++;
                }
                else break;
            }

            mx = max(mx, cnt);
        }
    }

    return mx;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1076 ms 25288 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -