Submission #966990

# Submission time Handle Problem Language Result Execution time Memory
966990 2024-04-20T19:50:55 Z AtabayRajabli Speedrun (RMI21_speedrun) C++17
100 / 100
69 ms 2364 KB
#include "speedrun.h"
#include <bits/stdc++.h>

using namespace std;

const int sz = 2005;
int cnt, num, in[sz], t[sz], p[sz];
vector<int> g[sz];

void dfs(int v)
{
    in[v] = ++cnt;
    t[in[v]] = v;
    for(int i : g[v])
    {
        if(!in[i])
        {
            p[i] = v;
            dfs(i);
        }
    }
}

void assignHints(int subtask, int N, int A[], int B[])
{
    for(int i = 1; i < N; i++)
    {
        g[A[i]].push_back(B[i]);
        g[B[i]].push_back(A[i]);
    }
    setHintLen(20);
    dfs(1);
    for(int i = 1; i <= N; i++)
    {
        int nxt = t[in[i] + 1];
        int prv = p[i];
        if(nxt == 0)nxt = 1;
        for(int j = 0; j < 10; j++)
        {
            if(prv & (1 << j)) setHint(i, (j + 11), 1);
            if(nxt & (1 << j)) setHint(i, (j + 1), 1);
        }
    }
}

void f(int go, int N)
{
    if(num == N)return;
    int nxt = 0, prv = 0;
    for(int i = 0; i < 10; i++)
    {
        nxt += getHint(i + 1) * (1 << i);
        prv += getHint(i + 11) * (1 << i);
    }
    if(go)
    {
        if(!goTo(go))
        {
            //cout << "could not go to " << go << ", went to " << prv << endl;
            goTo(prv);
            f(go, N);
        }
        else
        {
            num++;
            //cout << "went to " << go << endl;
            f(0, N);
        }
    }
    else
    {
        if(!goTo(nxt))
        {
            goTo(prv);
            //cout << "could not go to " << nxt << ", went to " << prv << endl;
            f(nxt, N);
        }
        else
        {
            //cout << "went to " << nxt << endl;
            num++;
            f(0, N);
        }
    }
}

void speedrun(int subtask, int N, int start)
{
    num = 1;
    f(0, N);
}
# Verdict Execution time Memory Grader output
1 Correct 53 ms 1688 KB Output is correct
2 Correct 66 ms 1416 KB Output is correct
3 Correct 54 ms 2364 KB Output is correct
4 Correct 54 ms 1856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 1424 KB Output is correct
2 Correct 46 ms 1864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 1420 KB Output is correct
2 Correct 68 ms 1364 KB Output is correct
3 Correct 59 ms 1172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 1676 KB Output is correct
2 Correct 56 ms 1424 KB Output is correct
3 Correct 61 ms 1712 KB Output is correct
4 Correct 61 ms 1680 KB Output is correct
5 Correct 69 ms 1412 KB Output is correct
6 Correct 57 ms 1604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 1420 KB Output is correct
2 Correct 63 ms 1664 KB Output is correct
3 Correct 55 ms 1676 KB Output is correct
4 Correct 60 ms 1428 KB Output is correct
5 Correct 52 ms 1360 KB Output is correct
6 Correct 49 ms 1412 KB Output is correct
7 Correct 56 ms 1864 KB Output is correct