답안 #498851

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
498851 2021-12-26T12:58:13 Z SlavicG Speedrun (RMI21_speedrun) C++17
100 / 100
168 ms 928 KB
#include "speedrun.h"
#include "bits/stdc++.h"
using namespace std;
 
#define pb push_back
#define sz(a) (int)a.size()
 
vector<int> st;
void dfsHint(int u, int par, vector<vector<int>>& adj, vector<int>& parent){
    st.pb(u);
    parent[u] = par;
    for(int v: adj[u]){
        if(v == par)continue;
        dfsHint(v, u, adj, parent);
    }
}
void assignHints(int subtask , int n, int a[], int b[]){
    setHintLen(20);
 
    vector<vector<int>> adj(n + 1);
    for(int i = 1;i <= n - 1; ++i){
        adj[a[i]].pb(b[i]);
        adj[b[i]].pb(a[i]);
    }  
    vector<int> right_neighbor(n + 1, 0), parent(n + 1, 0), left_child(n + 1, 0);
    dfsHint(1, 0, adj, parent);
    
    vector<int> nxt(n + 1, 0);
    for(int i = 0;i < sz(st); ++i){
        nxt[st[i]] = st[(i + 1) % sz(st)];
    }

    for(int i = 1;i <= n; ++i){
        int idx = 1;
        for(int j = 9;j >= 0; --j){
            if(parent[i] & (1 << j))setHint(i, idx, 1);
            ++idx;
        }
        for(int j = 9;j >= 0; --j){
            if(nxt[i] & (1 << j))setHint(i, idx, 1);
            ++idx;
        }
    }
}

int cnt;
void dfs(int u, vector<bool>& vis, int need){
    if(!vis[u])--cnt;
    vis[u] = true;
    if(!cnt)exit(0);
    int par = 0, nxt = 0, idx = 1;
 
    for(int j = 9;j >= 0; --j){
        if(getHint(idx))par += (1 << j);
        ++idx;
    }
    for(int j = 9;j >= 0; --j){
        if(getHint(idx))nxt += (1 << j);
        ++idx;
    }

    if(need == -1)need = nxt;

    int x = goTo(need);
    if(x){
        dfs(need, vis, -1);
    }else{
        assert(par != 0);
        goTo(par);
        dfs(par, vis, need);
    }
}

void speedrun(int subtask, int n, int start){
    int l = getLength();
    vector<bool> vis(n + 1, false);
    cnt = n;
    dfs(start, vis, -1);
}
 

Compilation message

speedrun.cpp: In function 'void speedrun(int, int, int)':
speedrun.cpp:75:9: warning: unused variable 'l' [-Wunused-variable]
   75 |     int l = getLength();
      |         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 704 KB Output is correct
2 Correct 118 ms 660 KB Output is correct
3 Correct 108 ms 664 KB Output is correct
4 Correct 155 ms 680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 100 ms 664 KB Output is correct
2 Correct 98 ms 788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 104 ms 668 KB Output is correct
2 Correct 106 ms 676 KB Output is correct
3 Correct 80 ms 696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 116 ms 660 KB Output is correct
2 Correct 120 ms 928 KB Output is correct
3 Correct 108 ms 704 KB Output is correct
4 Correct 105 ms 704 KB Output is correct
5 Correct 99 ms 668 KB Output is correct
6 Correct 119 ms 708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 788 KB Output is correct
2 Correct 123 ms 676 KB Output is correct
3 Correct 97 ms 664 KB Output is correct
4 Correct 142 ms 704 KB Output is correct
5 Correct 122 ms 704 KB Output is correct
6 Correct 168 ms 668 KB Output is correct
7 Correct 118 ms 796 KB Output is correct