Submission #873263

# Submission time Handle Problem Language Result Execution time Memory
873263 2023-11-14T17:39:18 Z bobbilyking Bosses (BOI16_bosses) C++17
100 / 100
379 ms 864 KB
#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include<bits/stdc++.h>
#include<math.h>
using namespace std;

typedef int ll;
typedef long double ld;
typedef pair<ll, ll> pl;

#define K first
#define V second
#define G(x) ll x; cin >> x;
#define GD(x) ld x; cin >> x;
#define GS(s) string s; cin >> s;
#define EX(x) { cout << x << '\n'; exit(0); }
#define A(a) (a).begin(), (a).end()
#define F(i, l, r) for (ll i = (l); i < r; ++i)

#define NN
#define M 1000000007 // 998244353

vector<ll> availWhenPlaced[5010];

int main(){
//    freopen("a.in", "r", stdin);
//    freopen("a.out", "w", stdout);

    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(20);
    G(n)
    F(i, 1, n+1) {
        G(k) while(k--) {
            G(t) availWhenPlaced[t].push_back(i);
        }
    }
    ll ans = n*n;
    F(root, 1, n+1) {
        vector<bool> vis(n+1); vector<ll> q{root}, nq; vis[root] = 1;
        ll tans = 0;
        for (ll dep = 1; q.size(); swap(q, nq), nq.clear(), dep++) {
            for (const auto &x: q) {
                tans += dep;
                for (const auto &y: availWhenPlaced[x]) if (!vis[y]) {
                    vis[y] = 1;
                    nq.push_back(y);
                }
            }
        }
        if (count(A(vis), true) == n) ans = min(ans, tans);
    }
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 572 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 572 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 424 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 572 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 424 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 4 ms 604 KB Output is correct
13 Correct 3 ms 664 KB Output is correct
14 Correct 91 ms 672 KB Output is correct
15 Correct 18 ms 600 KB Output is correct
16 Correct 379 ms 864 KB Output is correct
17 Correct 348 ms 784 KB Output is correct
18 Correct 348 ms 784 KB Output is correct