답안 #1039381

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1039381 2024-07-30T19:31:40 Z Zicrus 참나무 (IOI23_beechtree) C++17
0 / 100
2000 ms 1572 KB
#include <bits/stdc++.h>
#include "beechtree.h"
using namespace std;

typedef long long ll;

void dfs(vector<vector<ll>> &adj, ll cur) {
    vector<ll> nxt;
    for (auto &e : adj[cur]) {
        dfs(adj, e);
        for (auto &j : adj[e]) {
            nxt.push_back(j);
        }
    }
    for (auto &j : nxt) {
        adj[cur].push_back(j);
    }
}

bool isBeautiful(int &n, int &m, vector<int> &p, vector<int> &c, vector<vector<ll>> &adj, ll root) {
    sort(adj[root].begin(), adj[root].end());
    do {
        unordered_multiset<ll> numC;
        adj[root].insert(adj[root].begin(), root);
        for (auto &e : adj[root]) {
            if (e == root) continue;
            if (p[e] != adj[root][numC.count(c[e])]) goto skipThing;
            numC.insert(c[e]);
        }
        
        return true;
    skipThing:
        continue;
    } while (next_permutation(adj[root].begin(), adj[root].end()));
    
    return false;
}

vector<int> beechtree(int n, int m, vector<int> p, vector<int> c) {
    vector<int> res(n);
    vector<vector<ll>> adj(n);
    for (int i = 1; i < n; i++) {
        adj[p[i]].push_back(i);
    }
    dfs(adj, 0);

    for (int i = 0; i < n; i++) {
        res[i] = adj[i].empty() ? true : isBeautiful(n, m, p, c, adj, i);
    }

    return res;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Execution timed out 2078 ms 1544 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Execution timed out 2078 ms 1544 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2100 ms 1572 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Execution timed out 2078 ms 1544 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Execution timed out 2078 ms 1544 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Execution timed out 2078 ms 1544 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -