답안 #504856

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
504856 2022-01-10T09:15:36 Z daongocha Speedrun (RMI21_speedrun) C++14
19 / 100
234 ms 832 KB
#include <bits/stdc++.h>
 
#include "speedrun.h"
 
#define fileopen(a, b) freopen(((std::string)a + ".inp").c_str(), "r", stdin); freopen(((std::string)b + ".out").c_str(), "w", stdout);
#define fileopen1(a) freopen(((std::string)a + ".inp").c_str(), "r", stdin); freopen(((std::string)a + ".out").c_str(), "w", stdout);
 
using namespace std;
 
const int MAXN = 1005;
vector<int> path[MAXN];
vector<int> order;
int parent[MAXN];
 
// void assignHints(int subtask, int N, int A[], int B[]);
// void speedrun(int subtask, int N, int start);
 
// void setHintLen(int l);
// void setHint(int i, int j, bool b);
// int getLength();
// bool getHint(int j);
// bool goTo(int x);
 
void dfs(int u, int pre = 0) {
  //  cout << u << endl;
    order.push_back(u);
    parent[u] = pre;
    for (int v: path[u])
        if (v != pre) dfs(v, u);
}
 
void assignHints(int sub, int n, int A[], int B[]) {
    for (int i = 1; i < n; i++) {
        int u = A[i], v = B[i];
        path[u].push_back(v);
        path[v].push_back(u);
    }
    
    dfs(1);
 
    setHintLen(20);
    for (int i = n - 1; i >= 0; i--) {
        int u = order[i], v = (i + 1 >= n ? 0 : order[i + 1]);
        for (int j = 1; j <= 10; j++)
            setHint(u, j, (v >> (j - 1) & 1));
 
        for (int j = 11; j <= 20; j++)
            setHint(u, j, (parent[u] >> (j - 11) & 1));
    }
}
 
int nxt[MAXN], par[MAXN];
bool passed[MAXN];
int cnt = 0;
int tot;
 
void solve(int u, int go) {
    // cout << u << ' ' << go << endl;
    assert(u && u <= tot);
    if (!passed[u]) {
        passed[u] = 1;
        cnt++;
        for (int j = 0; j < 10; j++)
            nxt[u] |= (getHint(j + 1) << j);
 
        for (int j = 0; j < 10; j++) 
            par[u] |= (getHint(j + 11) << j);
 
        if (!passed[nxt[u]]) go = nxt[u];
    }
 
    if (cnt == tot) return;

    if (!go || !goTo(go)) {
        if (!par[u]) return;
        goTo(par[u]), solve(par[u], go);
    }
    else solve(go, 0);
}
 
void speedrun(int sub, int n, int start) {
    tot = n;
    solve(start, 0);
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 180 ms 712 KB Solution didn't visit every node
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 136 ms 832 KB Output is correct
2 Incorrect 99 ms 660 KB Solution didn't visit every node
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 708 KB Output is correct
2 Correct 234 ms 712 KB Output is correct
3 Correct 198 ms 788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 139 ms 668 KB Solution didn't visit every node
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 191 ms 732 KB Solution didn't visit every node
2 Halted 0 ms 0 KB -