Submission #536905

# Submission time Handle Problem Language Result Execution time Memory
536905 2022-03-14T07:09:02 Z dantoh000 Speedrun (RMI21_speedrun) C++14
60 / 100
117 ms 4752 KB
#include "speedrun.h"
#include <bits/stdc++.h>
using namespace std;
int arr1[1005][1005];
int arr2[1005][25];
vector<int> G[1005];
void assignHints(int subtask, int N, int A[], int B[]) { /* your solution here */
    if (subtask == 1){
        for (int i = 1; i < N; i++){
            arr1[A[i]][B[i]] = arr1[B[i]][A[i]] = 1;
        }

        setHintLen(N);
        for (int i = 1; i <= N; i++){
            for (int j = 1; j <= N; j++){
                if (arr1[i][j]) setHint(i,j,1);
            }
        }
    }
    if (subtask == 2){
        setHintLen(20);
        int ct[N];
        for (int i = 1; i <= N; i++) ct[i] = 0;
        for (int i = 1; i < N; i++){
            ct[A[i]]++;
            ct[B[i]]++;
        }
        int x = 0;
        for (int i = 1; i <= N; i++){
            if (ct[i] == N-1) x = i;
        }
        for (int i = 1; i <= N; i++){
            for (int j = 1; j <= 20; j++){
                if ((x>>(j-1))&1) setHint(i,j,1);
            }
        }
    }
    if (subtask == 3){
        setHintLen(20);
        for (int i = 1; i < N; i++){
            G[A[i]].push_back(B[i]);
            G[B[i]].push_back(A[i]);
        }
        for (int i = 1; i <= N; i++){
            for (int j = 1; j <= 10; j++){
                if ((G[i][0]>>(j-1))&1) setHint(i,j,1);
            }
            if (G[i].size() == 1) continue;
            for (int j = 11; j <= 20; j++){
                if ((G[i][1]>>(j-11))&1) setHint(i,j,1);
            }
        }
    }
    if (subtask == 4){
        setHintLen(316);
        for (int i = 1; i < N; i++){
            G[A[i]].push_back(B[i]);
            G[B[i]].push_back(A[i]);
        }
        for (int i = 1; i <= N; i++){
            for (int k = 0; k < min(31, (int)G[i].size()); k++){
                for (int j = k*10+1; j <= k*10+10; j++){
                    if ((G[i][k]>>(j-k*10-1))&1) setHint(i,j,1);
                }
            }
            if (G[i].size() >= 31){
                setHint(i, 316, 1);
            }
        }
    }
}
int n;
vector<int> G1[1005];
vector<int> G3[1005];
vector<int> G4[1005];
int vis4[1005];
void getG1(int u){
    for (int i = 1; i <= n; i++){
        if (getHint(i)){
            G1[u].push_back(i);
        }
    }
}

void getG3(int u){
    int x = 0;
    for (int i = 1; i <= 10; i++){
        if (getHint(i)) x += (1<<(i-1));
    }
    G3[u].push_back(x);
    x = 0;
    for (int i = 11; i <= 20; i++){
        if (getHint(i)) x += (1<<(i-11));
    }
    if (x) {
        G3[u].push_back(x);
    }
}

void getG4(int u){

    for (int k = 0; k < 31; k++){
        int x = 0;
        for (int j = k*10+1; j <= k*10+10; j++){
            if (getHint(j)) x += (1<<(j-k*10-1));
        }
        if (x) {
            G4[u].push_back(x);
            //printf("%d %d\n",u,x);
        }
    }
    if (getHint(316)){
        int last = G4[u].back();
        for (int i = last+1; i <= n; i++){
            if (vis4[i] == 0 && goTo(i)){
                //printf("%d %d\n",u,i);
                G4[u].push_back(i);
                goTo(u);
            }
        }
    }
}

void dfs1(int u, int p){
    getG1(u);
    for (auto v : G1[u]){
        if (v == p) continue;
        goTo(v);
        dfs1(v, u);
    }
    if (p != -1) goTo(p);
}

void dfs3(int u, int p){
    //printf("at %d\n",u);
    getG3(u);
    for (auto v : G3[u]){
        if (v == p) continue;
        //printf("%d %d\n",u,v);
        goTo(v);
        dfs3(v, u);
    }
    if (p != -1) goTo(p);
}

void dfs4(int u, int p){
    vis4[u] = 1;
    //printf("at %d\n",u);
    getG4(u);
    for (auto v : G4[u]){
        if (v == p) continue;
        //printf("%d %d\n",u,v);
        goTo(v);
        dfs4(v, u);
    }
    if (p != -1) goTo(p);
}



void speedrun(int subtask, int N, int start) { /* your solution here */
    n = N;
    if (subtask == 1){
        dfs1(start, -1);
    }
    if (subtask == 2){
        int x = 0;
        for (int i = 1; i <= 20; i++){
            if (getHint(i)) x += (1<<(i-1));
        }
        //printf("%d", x);
        if (start != x) goTo(x);
        for (int i = 1; i <= N; i++){
            if (i != x){
                goTo(i);
                goTo(x);
            }
        }
    }
    if (subtask == 3){
        dfs3(start, -1);
    }
    if (subtask == 4){
        dfs4(start, -1);
    }

}
# Verdict Execution time Memory Grader output
1 Correct 39 ms 4640 KB Output is correct
2 Correct 35 ms 4752 KB Output is correct
3 Correct 39 ms 4708 KB Output is correct
4 Correct 40 ms 4592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 804 KB Output is correct
2 Correct 46 ms 820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 932 KB Output is correct
2 Correct 92 ms 960 KB Output is correct
3 Correct 85 ms 924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 928 KB Output is correct
2 Correct 100 ms 932 KB Output is correct
3 Correct 117 ms 984 KB Output is correct
4 Correct 100 ms 964 KB Output is correct
5 Correct 103 ms 972 KB Output is correct
6 Correct 77 ms 968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB setHintLen was never called
2 Halted 0 ms 0 KB -