답안 #765357

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
765357 2023-06-24T11:30:46 Z vjudge1 Speedrun (RMI21_speedrun) C++17
40 / 100
156 ms 48348 KB
#include <bits/stdc++.h>
#include "speedrun.h"
using namespace std;
const int MAXN=1e3+5;
vector<int> sos[MAXN][MAXN];
int cnt[MAXN];
vector<vector<int> > g(MAXN);
void assignHints(int subtask, int N, int A[], int B[]) {
    if(subtask==1) {
        setHintLen(N);
        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(auto to : g[i])setHint(i, to, 1);
        }
    }
    if(subtask==2) {
        setHintLen(10);
        int x=0;
        for(int i=1; i<N; i++) {
            g[A[i]].push_back(B[i]);
            g[B[i]].push_back(A[i]);
            if(g[A[i]].size()>1)x=i;
        }
        if(x==0)x=1;
        for(int j=1; j<=10; j++)setHint(x, j, 1);
        for(int i=1; i<=N; i++) {
            if(i!=x) {
                for(int j=1; j<=10; j++) {
                    setHint(i, j, (x & (1<<(j-1)) ? 1 : 0));
                }
            }
        }
    }
    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++) {
            int cnt=0;
            for(auto to : g[i]) {
                if(cnt==0) {
                    for(int j=1; j<=10; j++) {
                        setHint(i, j, (to&(1<<(j-1)) ? 1 : 0));
                    }
                    cnt++;
                }else {
                    for(int j=11; j<=20; j++) {
                        setHint(i, j, (to&(1<<(j-11)) ? 1 : 0));
                    }
                }
            }
        }
    }
    return;
}
int us[MAXN];
void dfs(int v, int p, int N, int subtask) {
    us[v]=1;
    if(subtask==1) {
        vector<int> gg;
        for(int j=1; j<=N; j++) {
            if(getHint(j))gg.push_back(j);
        } 
        for(auto to : gg) {
            if(!us[to]) {
                goTo(to);
                dfs(to, v, N, subtask);
            }
        }
        if(v!=p)goTo(p);
        else return;
    }
    if(subtask==3) {
        vector<int> gg;
        int x=0, y=0;
        for(int j=1; j<=10; j++) {
            if(getHint(j))x+=(1<<(j-1));
        }
        for(int j=11; j<=20; j++) {
            if(getHint(j))y+=(1<<(j-11));
        }
        if(x>0)gg.push_back(x);
        if(y>0)gg.push_back(y);
        for(auto to : gg) {
            if(!us[to]) {
                goTo(to);
                dfs(to, v, N, subtask);
            }
        }
        if(v!=p)goTo(p);
        else return;
    }
}
void speedrun(int subtask, int N, int start) {
    if(subtask==1) {
        int len=getLength();
        dfs(start, start, N, subtask);
    }
    if(subtask==2) {
        int len=getLength();
        bool ok=1;
        for(int j=1; j<=10; j++) {
            if(!getHint(j)) {
                ok=0;
                break;
            }
        }
        if(ok) {
            for(int i=1; i<=N; i++) {
                if(start==i)continue;
                goTo(i);
                goTo(start);
            }
        }else {
            int x=0;
            for(int j=1; j<=10; j++) {
                if(getHint(j))x+=(1<<(j-1));
            }
            goTo(x);
            for(int i=1; i<=N; i++) {
                if(x==i)continue;
                goTo(i);
                goTo(x);
            }
        }
    }
    if(subtask==3) {
        int len=getLength();
        dfs(start, start, N, subtask);
    }
    return;
}

Compilation message

speedrun.cpp: In function 'void speedrun(int, int, int)':
speedrun.cpp:101:13: warning: unused variable 'len' [-Wunused-variable]
  101 |         int len=getLength();
      |             ^~~
speedrun.cpp:105:13: warning: unused variable 'len' [-Wunused-variable]
  105 |         int len=getLength();
      |             ^~~
speedrun.cpp:133:13: warning: unused variable 'len' [-Wunused-variable]
  133 |         int len=getLength();
      |             ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 48224 KB Output is correct
2 Correct 58 ms 48328 KB Output is correct
3 Correct 61 ms 48152 KB Output is correct
4 Correct 60 ms 48348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 82 ms 48028 KB Solution didn't visit every node
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 142 ms 48280 KB Output is correct
2 Correct 150 ms 48232 KB Output is correct
3 Correct 156 ms 48244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 24016 KB setHintLen was never called
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 24048 KB setHintLen was never called
2 Halted 0 ms 0 KB -