답안 #992042

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
992042 2024-06-03T16:58:57 Z stdfloat 봉쇄 시간 (IOI23_closing) C++17
9 / 100
1000 ms 25284 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;

vector<bool> vis;

vector<ll> c;

vector<vector<pii>> E;

bool dfs(int x, int p = -1, ll sm = 0) {
    bool tr = false;

    if (vis[x]) {
        tr = true;
        c[x] = max(c[x], sm);
    }

    for (auto [i, w] : E[x]) {
        if (i != p && dfs(i, x, sm + w)) {
            tr = true;
            c[x] = max(c[x], sm);
        }
    }

    return tr;
}

vector<ll> f(int st, int n) {
    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;
}

int max_score(int n, int X, int Y, long long K, vector<int> U, vector<int> V, vector<int> W) {
    E.assign(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]});
    }

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

    if (n <= 20) {
        vector<pii> u;
        for (int i = 0; i < n; i++)
            u.push_back({min(disx[i], disy[i]), i});

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

        int mx = 0;
        for (int mk = 0; mk < (1 << n); mk++) {
            c.assign(n, -1);
            vis.assign(n, false);
            for (int i = 0; i < n; i++)
                vis[i] = (mk >> i) & 1;

            dfs(X); dfs(Y);

            ll sm = 0;
            int cnt = 0;
            for (int i = 0; i < n && sm <= K; i++) {
                if (c[i] != -1) {
                    sm += c[i];
                    cnt += 1 + (c[i] != min(disx[i], disy[i]));
                }
            }

            ll z = sm, z1 = cnt;
            
            if (sm > K) continue;

            for (int i = 0; i < n; i++) {
                if (c[u[i].ss] == -1) {
                    if ((sm += u[i].ff) > K) break;
                    cnt++;
                }
            }

            mx = max(mx, cnt);
        }

        return mx;
    }

    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) 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 = 0;
            for (auto k : c)
                if (k != -1) sm += k;

            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 = 0;
            for (int i = 0; i < n; i++)
                if (c[i] != -1) cnt += 1 + (c[i] != min(disx[i], disy[i]));

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

            mx = max(mx, cnt);
        }
    }

    return mx;
}

Compilation message

closing.cpp: In function 'int max_score(int, int, int, long long int, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:87:16: warning: unused variable 'z' [-Wunused-variable]
   87 |             ll z = sm, z1 = cnt;
      |                ^
closing.cpp:87:24: warning: unused variable 'z1' [-Wunused-variable]
   87 |             ll z = sm, z1 = cnt;
      |                        ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1052 ms 25284 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 365 ms 412 KB Output is correct
3 Correct 354 ms 348 KB Output is correct
4 Correct 397 ms 348 KB Output is correct
5 Correct 172 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 365 ms 412 KB Output is correct
3 Correct 354 ms 348 KB Output is correct
4 Correct 397 ms 348 KB Output is correct
5 Correct 172 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 3 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 3 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Execution timed out 1100 ms 348 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 365 ms 412 KB Output is correct
3 Correct 354 ms 348 KB Output is correct
4 Correct 397 ms 348 KB Output is correct
5 Correct 172 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 3 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 3 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Execution timed out 1100 ms 348 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 365 ms 412 KB Output is correct
4 Correct 354 ms 348 KB Output is correct
5 Correct 397 ms 348 KB Output is correct
6 Correct 172 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '9', found: '7'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 365 ms 412 KB Output is correct
4 Correct 354 ms 348 KB Output is correct
5 Correct 397 ms 348 KB Output is correct
6 Correct 172 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 3 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '9', found: '7'
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 365 ms 412 KB Output is correct
4 Correct 354 ms 348 KB Output is correct
5 Correct 397 ms 348 KB Output is correct
6 Correct 172 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 3 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Execution timed out 1100 ms 348 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 365 ms 412 KB Output is correct
4 Correct 354 ms 348 KB Output is correct
5 Correct 397 ms 348 KB Output is correct
6 Correct 172 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 3 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Execution timed out 1100 ms 348 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 365 ms 412 KB Output is correct
4 Correct 354 ms 348 KB Output is correct
5 Correct 397 ms 348 KB Output is correct
6 Correct 172 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 3 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Execution timed out 1100 ms 348 KB Time limit exceeded
20 Halted 0 ms 0 KB -