답안 #536969

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
536969 2022-03-14T08:28:04 Z joelau Speedrun (RMI21_speedrun) C++14
48 / 100
120 ms 836 KB
#include "speedrun.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> lst[1005];

void assignHints(int subtask, int N, int A[], int B[]) {
	if (subtask == 1) {
	    setHintLen(N);
    	for (int i = 1; i < N; ++i) setHint(A[i],B[i],1), setHint(B[i],A[i],1);
    }
    if (subtask == 2) {
        int deg[N+5];
        memset(deg,0,sizeof(deg));
        for (int i = 1; i < N; ++i) deg[A[i]]++, deg[B[i]]++;
        int x = 1;
        for (int i = 1; i <= N; ++i) if (deg[i] > deg[x]) x = i;
        setHintLen(20);
        for (int i = 0; i < 20; ++i) for (int j = 1; j <= N; ++j) if (x & (1<<i)) setHint(j,i+1,1);
    }
    if (subtask == 3) {
        setHintLen(20);
        for (int i = 1; i < N; ++i) lst[A[i]].push_back(B[i]), lst[B[i]].push_back(A[i]);
        for (int i = 1; i <= N; ++i) {
            for (int j = 0; j < 10; ++j) if (lst[i][0] & (1<<j)) setHint(i,j+1,1);
            if (lst[i].size() > 1) {
                for (int j = 0; j < 10; ++j) if (lst[i][1] & (1<<j)) setHint(i,j+11,1);
            }
            else {
                for (int j = 0; j < 10; ++j) if (i & (1<<j)) setHint(i,j+11,1);
            }
        }
    }
}

int n;

void dfs (int x, int p) {
    for (int i = 1; i <= n; ++i) if (i != p && getHint(i)) {
        goTo(i);
        dfs(i,x);
    }
    if (p != -1) goTo(p);
}

void dfs2 (int x, int p) {
    int a = 0, b = 0;
    for (int i = 0; i < 10; ++i) if (getHint(i+1)) a |= (1<<i);
    for (int i = 0; i < 10; ++i) if (getHint(i+11)) b |= (1<<i);
    if (a != p) goTo(a), dfs2(a,x);
    if (b != x && b != p) goTo(b), dfs2(b,x);
    if (p != -1) goTo(p);
}

void speedrun(int subtask, int N, int start) {
    int len = getLength();
  	if (subtask == 1) {
    	n = N;
    	dfs(start,-1);
    }
    if (subtask == 2) {
        bitset<1005> visited;
        visited[start] = 1;
        int x = 0;
        for (int i = 0; i < 20; ++i) if (getHint(i+1)) x |= (1<<i);
        if (start != x) goTo(x), visited[x] = 1;
        for (int i = 1; i <= N; ++i) if (!visited[i]) goTo(i), goTo(x);
    }
    if (subtask == 3) {
        n = N;
        dfs2(start,-1);
    }
}

Compilation message

speedrun.cpp: In function 'void speedrun(int, int, int)':
speedrun.cpp:56:9: warning: unused variable 'len' [-Wunused-variable]
   56 |     int len = getLength();
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 788 KB Output is correct
2 Correct 37 ms 796 KB Output is correct
3 Correct 44 ms 788 KB Output is correct
4 Correct 42 ms 812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 728 KB Output is correct
2 Correct 41 ms 836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 120 ms 780 KB Output is correct
2 Correct 94 ms 716 KB Output is correct
3 Correct 73 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB setHintLen was never called
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB setHintLen was never called
2 Halted 0 ms 0 KB -