답안 #641951

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
641951 2022-09-18T00:36:56 Z skittles1412 Meetings 2 (JOI21_meetings2) C++17
4 / 100
4000 ms 62420 KB
#include "bits/extc++.h"

using namespace std;

template <typename T>
void dbgh(const T& t) {
    cerr << t << endl;
}

template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
    cerr << t << " | ";
    dbgh(u...);
}

#ifdef DEBUG
#define dbg(...)                                           \
    cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
         << ": ";                                          \
    dbgh(__VA_ARGS__)
#else
#define cerr   \
    if (false) \
    cerr
#define dbg(...)
#endif

#define endl "\n"
#define long int64_t
#define sz(x) int(std::size(x))

/*constexpr int maxn = 4e3 + 5;

int siz[maxn], depth[maxn], par1[maxn];
vector<int> graph[maxn];

void pdfs(int u, int p = -1, int d = 0, int p1 = -1) {
    if (d == 1) {
        p1 = u;
    }
    siz[u] = 1;
    depth[u] = d;
    par1[u] = p1;
    for (auto& v : graph[u]) {
        if (v != p) {
            pdfs(v, u, d + 1, p1);
            siz[u] += siz[v];
        }
    }
}

void solve() {
    int n;
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    int ans[n + 1] {};
    ans[n] = 1;
    for (int i = 0; i < n; i++) {
        pdfs(i);
        for (int j = 0; j < n; j++) {
            if (par1[j] != -1) {
                int& mans = ans[min(n - siz[par1[j]], siz[j])];
                mans = max(mans, depth[j] + 1);
            }
        }
    }
    for (int i = n - 1; i >= 0; i--) {
        ans[i] = max(ans[i], ans[i + 1]);
    }
    for (int i = 1; i <= n; i++) {
        if (i & 1) {
            cout << 1 << endl;
        } else {
            cout << ans[i / 2] << endl;
        }
    }
}*/

bool on(int mask, int bit) {
    return (mask >> bit) & 1;
}

void solve() {
    int n;
    cin >> n;
    int dist[n][n];
    memset(dist, 0x3f, sizeof(dist));
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        dist[u][v] = dist[v][u] = 1;
    }
    for (int i = 0; i < n; i++) {
        dist[i][i] = 0;
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
    int ans[n + 1] {};
    for (int i = 1; i < (1 << n); i++) {
        pair<int, int> opt {1e9, -1};
        for (int j = 0; j < n; j++) {
            int cans = 0;
            for (int k = 0; k < n; k++) {
                if (on(i, k)) {
                    cans += dist[j][k];
                }
            }
            if (cans < opt.first) {
                opt = {cans, 1};
            } else if (cans == opt.first) {
                opt.second++;
            }
        }
        int& mans = ans[__builtin_popcount(i)];
        mans = max(mans, opt.second);
    }
    for (int i = 1; i <= n; i++) {
        cout << ans[i] << endl;
    }
}

int main() {
    cin.tie(nullptr);
    cin.exceptions(ios::failbit);
    ios_base::sync_with_stdio(false);
    solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 7 ms 316 KB Output is correct
5 Correct 7 ms 212 KB Output is correct
6 Correct 7 ms 324 KB Output is correct
7 Correct 7 ms 212 KB Output is correct
8 Correct 13 ms 212 KB Output is correct
9 Correct 28 ms 212 KB Output is correct
10 Correct 27 ms 212 KB Output is correct
11 Correct 28 ms 212 KB Output is correct
12 Correct 28 ms 212 KB Output is correct
13 Correct 26 ms 212 KB Output is correct
14 Correct 7 ms 316 KB Output is correct
15 Correct 7 ms 212 KB Output is correct
16 Correct 13 ms 324 KB Output is correct
17 Correct 28 ms 212 KB Output is correct
18 Correct 31 ms 212 KB Output is correct
19 Correct 13 ms 212 KB Output is correct
20 Correct 37 ms 212 KB Output is correct
21 Correct 14 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 7 ms 316 KB Output is correct
5 Correct 7 ms 212 KB Output is correct
6 Correct 7 ms 324 KB Output is correct
7 Correct 7 ms 212 KB Output is correct
8 Correct 13 ms 212 KB Output is correct
9 Correct 28 ms 212 KB Output is correct
10 Correct 27 ms 212 KB Output is correct
11 Correct 28 ms 212 KB Output is correct
12 Correct 28 ms 212 KB Output is correct
13 Correct 26 ms 212 KB Output is correct
14 Correct 7 ms 316 KB Output is correct
15 Correct 7 ms 212 KB Output is correct
16 Correct 13 ms 324 KB Output is correct
17 Correct 28 ms 212 KB Output is correct
18 Correct 31 ms 212 KB Output is correct
19 Correct 13 ms 212 KB Output is correct
20 Correct 37 ms 212 KB Output is correct
21 Correct 14 ms 212 KB Output is correct
22 Execution timed out 4042 ms 62420 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 7 ms 316 KB Output is correct
5 Correct 7 ms 212 KB Output is correct
6 Correct 7 ms 324 KB Output is correct
7 Correct 7 ms 212 KB Output is correct
8 Correct 13 ms 212 KB Output is correct
9 Correct 28 ms 212 KB Output is correct
10 Correct 27 ms 212 KB Output is correct
11 Correct 28 ms 212 KB Output is correct
12 Correct 28 ms 212 KB Output is correct
13 Correct 26 ms 212 KB Output is correct
14 Correct 7 ms 316 KB Output is correct
15 Correct 7 ms 212 KB Output is correct
16 Correct 13 ms 324 KB Output is correct
17 Correct 28 ms 212 KB Output is correct
18 Correct 31 ms 212 KB Output is correct
19 Correct 13 ms 212 KB Output is correct
20 Correct 37 ms 212 KB Output is correct
21 Correct 14 ms 212 KB Output is correct
22 Execution timed out 4042 ms 62420 KB Time limit exceeded
23 Halted 0 ms 0 KB -