Submission #1081975

# Submission time Handle Problem Language Result Execution time Memory
1081975 2024-08-30T13:38:06 Z Boas Closing Time (IOI23_closing) C++17
9 / 100
103 ms 10076 KB
#include "closing.h"

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T1, typename T2>
using indexed_map = tree<T1, T2, less<T1>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long
#define pb push_back
#define loop(x, i) for (int i = 0; i < x; i++)
#define rev(x, i) for (int i = (int)(x) - 1; i >= 0; i--)
#define ALL(x) begin(x), end(x)
typedef pair<int, int> ii;
typedef signed i32;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<i32> vi32;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

i32 max_score(i32 N, i32 X, i32 Y, int K, vi32 U, vi32 V, vi32 W)
{
    assert(N <= 20);
    vvii adj(N);
    loop(N - 1, i)
    {
        adj[U[i]].pb({V[i], W[i]});
        adj[V[i]].pb({U[i], W[i]});
    }
    vi xTime(N), yTime(N);
    auto dfs = [&](auto &&self, int i, int prev, vi &time) -> void
    {
        for (auto [j, w] : adj[i])
        {
            if (j == prev)
                continue;
            time[j] = time[i] + w;
            self(self, j, i, time);
        }
    };
    dfs(dfs, X, X, xTime);
    dfs(dfs, Y, Y, yTime);
    vi maxTime(N);
    loop(N, i) maxTime[i] = max(xTime[i], yTime[i]);
    int res = 0;
    for (unsigned mask = 0; mask < (1 << N); mask++)
    {
        int cur = 2 * __popcount(mask);
        int sum = 0;
        int first = -1;
        vb added(N);
        loop(N, i)
        {
            if ((1 << i) & mask)
            {
                added[i] = 1;
                first = i;
                sum += maxTime[i];
            }
        }
        int connected = 0;
        auto dfs2 = [&](auto &&self, int i, int prev) -> void
        {
            if (!added[i])
                return;
            if ((1 << i) & mask)
                connected++;
            for (auto [j, w] : adj[i])
            {
                if (j == prev)
                    continue;
                self(self, j, i);
            }
        };
        if (first != -1)
            dfs2(dfs2, first, first);
        if (connected != __popcount(mask))
            continue;
        if (sum > K)
        {
            continue;
        }
        vb vis(N);
        priority_queue<ii> q;
        q.push({0, X});
        q.push({0, Y});
        while (!q.empty())
        {
            auto [d, i] = q.top();
            q.pop();
            if (vis[i])
                continue;
            vis[i] = 1;
            if (!((1 << i) & mask))
            {
                cur++;
                sum -= d;
            }
            if (sum > K)
            {
                cur--;
                break;
            }
            added[i] = 1;
            for (auto [j, w] : adj[i])
            {
                if (vis[j])
                    continue;
                q.push({d - w, j});
            }
        }
        connected = 0;
        dfs2(dfs2, X, X);
        if (connected != __popcount(mask))
            continue;
        connected = 0;
        dfs2(dfs2, Y, Y);
        if (connected != __popcount(mask))
            continue;
        if (cur > res)
        {
            res = cur;
        }
    }
    return res;
}

Compilation message

closing.cpp: In function 'i32 max_score(i32, i32, i32, long long int, vi32, vi32, vi32)':
closing.cpp:49:34: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
   49 |     for (unsigned mask = 0; mask < (1 << N); mask++)
      |                             ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 39 ms 10076 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 86 ms 348 KB Output is correct
3 Correct 81 ms 344 KB Output is correct
4 Correct 85 ms 408 KB Output is correct
5 Correct 44 ms 348 KB Output is correct
6 Runtime error 1 ms 348 KB Execution killed with signal 6
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 86 ms 348 KB Output is correct
3 Correct 81 ms 344 KB Output is correct
4 Correct 85 ms 408 KB Output is correct
5 Correct 44 ms 348 KB Output is correct
6 Runtime error 1 ms 348 KB Execution killed with signal 6
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 86 ms 348 KB Output is correct
3 Correct 81 ms 344 KB Output is correct
4 Correct 85 ms 408 KB Output is correct
5 Correct 44 ms 348 KB Output is correct
6 Runtime error 1 ms 348 KB Execution killed with signal 6
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 86 ms 348 KB Output is correct
4 Correct 81 ms 344 KB Output is correct
5 Correct 85 ms 408 KB Output is correct
6 Correct 44 ms 348 KB Output is correct
7 Correct 1 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 23 ms 436 KB Output is correct
11 Correct 47 ms 344 KB Output is correct
12 Correct 3 ms 344 KB Output is correct
13 Correct 98 ms 344 KB Output is correct
14 Correct 52 ms 596 KB Output is correct
15 Correct 25 ms 428 KB Output is correct
16 Correct 25 ms 348 KB Output is correct
17 Correct 25 ms 348 KB Output is correct
18 Correct 48 ms 348 KB Output is correct
19 Correct 102 ms 412 KB Output is correct
20 Correct 27 ms 344 KB Output is correct
21 Correct 24 ms 348 KB Output is correct
22 Correct 103 ms 412 KB Output is correct
23 Correct 93 ms 348 KB Output is correct
24 Correct 25 ms 440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 86 ms 348 KB Output is correct
4 Correct 81 ms 344 KB Output is correct
5 Correct 85 ms 408 KB Output is correct
6 Correct 44 ms 348 KB Output is correct
7 Runtime error 1 ms 348 KB Execution killed with signal 6
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 86 ms 348 KB Output is correct
4 Correct 81 ms 344 KB Output is correct
5 Correct 85 ms 408 KB Output is correct
6 Correct 44 ms 348 KB Output is correct
7 Runtime error 1 ms 348 KB Execution killed with signal 6
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 86 ms 348 KB Output is correct
4 Correct 81 ms 344 KB Output is correct
5 Correct 85 ms 408 KB Output is correct
6 Correct 44 ms 348 KB Output is correct
7 Runtime error 1 ms 348 KB Execution killed with signal 6
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 86 ms 348 KB Output is correct
4 Correct 81 ms 344 KB Output is correct
5 Correct 85 ms 408 KB Output is correct
6 Correct 44 ms 348 KB Output is correct
7 Runtime error 1 ms 348 KB Execution killed with signal 6
8 Halted 0 ms 0 KB -