Submission #736890

# Submission time Handle Problem Language Result Execution time Memory
736890 2023-05-06T10:15:57 Z puppy Speedrun (RMI21_speedrun) C++17
0 / 100
1 ms 464 KB
#include "speedrun.h"
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

void assignHints(int subtask, int N, int A[], int B[]) { /* your solution here */
    setHintLen(20);
    vector<vector<int>> adj(N+1), g(N+1);
    for (int i = 1; i < N; i++) {
        adj[A[i]].push_back(B[i]);
        adj[B[i]].push_back(A[i]);
    }
    int last_leaf = -1;
    function<void(int, int)> settree = [&](int v, int p)
    {
        g[p].push_back(v);
        for (int i:adj[v]) {
            if (i != p) settree(i, v);
        }
    };
    settree(1, 0);
    //앞 10개에 부모의 정보 저장
    function<void(int, int)> dfs = [&](int v, int p)
    {
        for (int i = 0; i < 10; i++) {
            setHint(v, i, (p >> i) & 1);
        }
        if (g[v].empty()) {
            last_leaf = v;
            return;
        }
        for (int i = 10; i < 20; i++) {
            setHint(v, i, (g[v][0] >> (i - 10)) & 1);
        }
        for (int i = 0; i < (int)g[v].size(); i++) {
            if (i >= 1) {
                //g[v][i]를 last_leaf에 부여
                for (int k = 10; k < 20; k++) {
                    setHint(last_leaf, k, (g[v][i] >> (k - 10)) & 1);
                }
            }
            dfs(g[v][i], v);
        }
    };
    dfs(1, 0);
}

void speedrun(int subtask, int N, int start) { /* your solution here */
    //start
    //자식 방문하기
    function<int()> par = [&]()
    {
        int ret = 0;
        for (int i = 9; i >= 0; i--) {
            ret <<= 1;
            ret += getHint(i);
        }
        return ret;
    };
    function<int()> chd = [&]()
    {
        int ret = 0;
        for (int i = 19; i >= 10; i--) {
            ret <<= 1;
            ret += getHint(i);
        }
        return ret;
    };
    vector<int> chd_cnt(N+1);
    int cur = start;
    int mmr = -1;
    while (1) {
        //cur의 자식을 일단 모두 방문
        //chd_cnt번째 자식 방문할 차례
        if (chd_cnt[cur] == 0) {
            bool suc = goTo(chd());
            if (suc) {
                chd_cnt[cur]++;
                cur = chd();
                continue;
            }
            else {
                mmr = chd();
                if (par() == 0) return;
                else {
                    cur = par();
                    goTo(par());
                }
            }
        }
        else {
            if (goTo(mmr)) {
                cur = mmr;
                continue;
            }
            else {
                if (par() == 0) return;
                else {
                    cur = par();
                    goTo(par());
                }
            }
        }
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Invalid bit index for setHint
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Invalid bit index for setHint
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 464 KB Invalid bit index for setHint
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Invalid bit index for setHint
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Invalid bit index for setHint
2 Halted 0 ms 0 KB -