답안 #770785

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
770785 2023-07-01T23:59:54 Z gg123_pe Speedrun (RMI21_speedrun) C++14
82 / 100
146 ms 920 KB
#include "speedrun.h"
#include <bits/stdc++.h> 

using namespace std; 

#define f(i,a,b) for(int i = a; i < b; i++)
const int N = 1005; 

void setHintLen (int l);
void setHint(int i, int j, bool b);
int getLength ();
bool getHint(int j);
bool goTo(int x);

int n; 
int p[N]; 
vector <int> adj[N], curr, order; 
bool vis[N]; 

void dfs(int u, int f){
    curr.push_back(u);
    order.push_back(u); 

    p[u] = f; 

    for(int v: adj[u]){
        if(v == f) continue; 
        dfs(v, u); 
    }
    if(f != 0) curr.push_back(f); 
}
void assign(int node, int pos, int val){
    int l = 10*(pos-1) + 1, r = 10*pos;
    f(i,l,r+1){
        int x = i - l; 
        if(val&(1<<x)) setHint(node, i, 1);
    } 
}
void assignHints(int subtask, int Ni, int A[], int B[]) { 
    n = Ni; 
    f(i,1,n){
        adj[A[i]].push_back(B[i]); 
        adj[B[i]].push_back(A[i]); 
    }

    if(subtask == 2){
        setHintLen(1); 
        f(i,1,n+1){
            if(adj[i].size() == n-1){
                setHint(i, 1, 1); 
                break; 
            }
        }
        return; 
    }
    if(subtask == 3){
        setHintLen(20); 
        int l; 
        f(i,1,n+1){
            if(adj[i].size() == 1){
                l = i; 
                break; 
            }
        }
        dfs(l, 0); 
        f(i,0,n){
            int node = order[i]; 
            if(i > 0) assign(node, 1, order[i-1]); 
            if(i+1 < n) assign(node, 2, order[i+1]); 
        }
        return; 
    }
    setHintLen(30);
    dfs(1, 0); 

    int id = 0; 
    f(i,0,n){
        int node = order[i]; 
        assign(node, 1, p[node]); 
        assign(node, 2, curr[id++]);
        assign(node, 3, curr[id++]);   
    }
}
int get(int pos){
    int ans = 0, l = 10*(pos-1) + 1, r = 10*pos;
    f(i,l,r+1){
        int x = i-l; 
        if(getHint(i)) ans ^= (1<<x); 
    }
    return ans; 
}
void speedrun(int subtask, int Ni, int start) { 
    n = Ni; 

    if(subtask == 2){
        int root = start; 
        if(!getHint(1)){
            f(i,1,n+1){
                if(i != start and goTo(i)){
                    root = i; 
                    break; 
                }
            }
            f(i,1,n+1){
                if(i != root){
                    goTo(i); 
                    goTo(root);
                }
            }
        }
        return; 
    }
    if(subtask == 3){
        while(1){
            int r = get(2); 
            if(r == 0) break; 
            start = r; 
            goTo(start); 
        }
        while(1){
            int l = get(1); 
            if(l == 0) break; 
            start = l; 
            goTo(start); 
        }
        return; 
    }
    while(start != 1) {
        start = get(1); 
        goTo(start); 
    }
     
    if(get(2) != 0) curr.push_back(get(2));
    if(get(3) != 0) curr.push_back(get(3));   
    int id = 1; 
    vis[1] = 1;  

    while(id < (int) curr.size()){
        int node = curr[id]; 
        if(!goTo(node))
            return; 
        
        if(!vis[node]){
            vis[node] = 1; 
            if(get(2) != 0) curr.push_back(get(2));
            if(get(3) != 0) curr.push_back(get(3));   
        }
        id++; 
    }
}

Compilation message

speedrun.cpp: In function 'void assignHints(int, int, int*, int*)':
speedrun.cpp:49:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   49 |             if(adj[i].size() == n-1){
      |                ~~~~~~~~~~~~~~^~~~~~
speedrun.cpp:65:12: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
   65 |         dfs(l, 0);
      |         ~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 672 KB Output is correct
2 Correct 123 ms 808 KB Output is correct
3 Correct 66 ms 836 KB Output is correct
4 Correct 143 ms 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 752 KB Solution didn't visit every node
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 920 KB Output is correct
2 Correct 92 ms 868 KB Output is correct
3 Correct 95 ms 800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 120 ms 884 KB Output is correct
2 Correct 120 ms 740 KB Output is correct
3 Correct 99 ms 772 KB Output is correct
4 Correct 127 ms 740 KB Output is correct
5 Correct 133 ms 892 KB Output is correct
6 Correct 124 ms 796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 141 ms 760 KB Partial solution
2 Partially correct 116 ms 700 KB Partial solution
3 Partially correct 63 ms 748 KB Partial solution
4 Partially correct 103 ms 816 KB Partial solution
5 Partially correct 97 ms 768 KB Partial solution
6 Partially correct 146 ms 748 KB Partial solution
7 Partially correct 81 ms 780 KB Partial solution