Submission #850751

# Submission time Handle Problem Language Result Execution time Memory
850751 2023-09-17T11:37:38 Z Itamar Speedrun (RMI21_speedrun) C++14
60 / 100
3500 ms 41792 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++;
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 303 ms 1984 KB Output is correct
2 Execution timed out 3519 ms 26436 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 149 ms 1848 KB Output is correct
2 Correct 152 ms 1840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3518 ms 41792 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 960 ms 5060 KB Output is correct
2 Correct 364 ms 2240 KB Output is correct
3 Correct 200 ms 2256 KB Output is correct
4 Correct 3343 ms 19664 KB Output is correct
5 Correct 630 ms 3748 KB Output is correct
6 Correct 160 ms 1736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 603 ms 4020 KB Output is correct
2 Correct 388 ms 2224 KB Output is correct
3 Correct 216 ms 1484 KB Output is correct
4 Correct 2881 ms 22672 KB Output is correct
5 Correct 226 ms 1688 KB Output is correct
6 Correct 691 ms 3788 KB Output is correct
7 Correct 136 ms 1596 KB Output is correct