답안 #850750

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
850750 2023-09-17T11:37:05 Z Itamar Speedrun (RMI21_speedrun) C++14
컴파일 오류
0 ms 0 KB
#define pi pair<int,int>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
#define vi vector<int>
//#include "speedrun.h"
using namespace std;
void seth(int i, pi p) {
    for (int j = 1; j <= 10; j++) {
        setHint(i, j, p.first % 2);
        p.first /= 2;
    }
    for (int j = 11; j <= 20; j++) {
        setHint(i, j, p.second % 2);
        p.second /= 2;
    }
}
pi get() {
    pi ans;
    int j = 1;
    for (int i = 1; i < 1024; i*=2) {
        ans.first += getHint(j) * i;
        j++;
    }
    for (int i = 1; i < 1024; i *= 2) {
        ans.second += getHint(j) * i;
        j++;
    }
    return ans;
}
void dfs(int i, vi&pad, vector<vi> fr) {
    for (int f : fr[i]) {
        if (f != pad[i]) {
            pad[f] = i;
            dfs(f,pad,fr);
        }
    }
}
#include <queue>
void assignHints(int subtask, int N, int A[], int B[]) {
    /* your solution here */
    setHintLen(20);
    if (N == 1)return;
    vector<vi> fr(N + 1);
    for (int i = 1; i < N; i++) {
        fr[A[i]].push_back(B[i]);
        fr[B[i]].push_back(A[i]);
    }
    vi pad(N + 1);
    vector<vi> son(N + 1);
    dfs(1, pad, fr);
    for (int i = 2; i <= N; i++) {
        son[pad[i]].push_back(i);
    }
    /*for (int i = 1; i <= N; i++) {
        if (son[i].empty())son[i].push_back(0);
    }*/
    vi v;
    queue<int> q;
    q.push(1);
    while (!q.empty()) {
        int i = q.front();
        q.pop();
        v.push_back(i);
        for (int f : son[i]) {
            q.push(f);
        }
    }
    v.push_back(0);
    for (int i = 0; i < N; i++) {
        seth(v[i], { pad[v[i]],v[i + 1] });
    }/*
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j < son[i].size(); j++) {
            int s = son[i][j];
            if (s == 0)break;
            if (s == son[i].back()) {
                seth(s, { son[s][0],i });
            }
            else {
                seth(s, { son[s][0],son[i][j + 1] });
            }
        }
    }
    seth(1, { son[1][0],0 });*/
}
void walk(int a, int b, vi pad) {
    while (a != 1) {
        pi p = get();
        a = p.first;
        goTo(p.first);
    }
    vi v={b};
    while (b != 1) {
        v.push_back(pad[b]);
        b = pad[b];
    }
    for (int i = v.size() - 2; i >= 0; i--) {
        goTo(v[i]);
    }
}
void speedrun(int subtask, int N, int start) {
    if (N == 1)return;
    int x = start;
    while (x != 1) {
        pi p = get();
        x = p.first;
        goTo(p.first);
    }
    vi v = { 1 };
    int it = 0;
    vi pad(N + 1);
    for (int i = 0; i < N - 1; i++) {
        v.push_back(get().second);
        
        while (true) {
            walk(x, v[it], pad);
            x = v[it];
            if (goTo(v.back())) {
                x = v.back();
                pad[x] = v[it];
                break;
            }
            else it++;
        }
    }
}

Compilation message

speedrun.cpp: In function 'void seth(int, std::pair<int, int>)':
speedrun.cpp:12:9: error: 'setHint' was not declared in this scope
   12 |         setHint(i, j, p.first % 2);
      |         ^~~~~~~
speedrun.cpp:16:9: error: 'setHint' was not declared in this scope
   16 |         setHint(i, j, p.second % 2);
      |         ^~~~~~~
speedrun.cpp: In function 'std::pair<int, int> get()':
speedrun.cpp:24:22: error: 'getHint' was not declared in this scope; did you mean 'getline'?
   24 |         ans.first += getHint(j) * i;
      |                      ^~~~~~~
      |                      getline
speedrun.cpp:28:23: error: 'getHint' was not declared in this scope; did you mean 'getline'?
   28 |         ans.second += getHint(j) * i;
      |                       ^~~~~~~
      |                       getline
speedrun.cpp: In function 'void assignHints(int, int, int*, int*)':
speedrun.cpp:44:5: error: 'setHintLen' was not declared in this scope
   44 |     setHintLen(20);
      |     ^~~~~~~~~~
speedrun.cpp: In function 'void walk(int, int, std::vector<int>)':
speedrun.cpp:93:9: error: 'goTo' was not declared in this scope
   93 |         goTo(p.first);
      |         ^~~~
speedrun.cpp:101:9: error: 'goTo' was not declared in this scope
  101 |         goTo(v[i]);
      |         ^~~~
speedrun.cpp: In function 'void speedrun(int, int, int)':
speedrun.cpp:110:9: error: 'goTo' was not declared in this scope
  110 |         goTo(p.first);
      |         ^~~~
speedrun.cpp:121:17: error: 'goTo' was not declared in this scope
  121 |             if (goTo(v.back())) {
      |                 ^~~~