답안 #645836

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
645836 2022-09-28T07:10:27 Z MadokaMagicaFan Speedrun (RMI21_speedrun) C++14
29 / 100
37 ms 924 KB
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using vi = vector<int>;
using pi = pair<int, int>;

#define forn(i,n)   for(int i = 0; i < n; ++i)
#define forb(i,b,n)   for(int i = b; i < n; ++i)
#define pb          push_back
#define sz(v)       ((int)((v).size()))

/* #define ONPC */

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

void
assignHints(int s, int n, int *a, int *b)
{
    if (s == 1) {
        setHintLen(n);
        forb(i,1,n) {
            setHint(a[i], b[i], 1);
            setHint(b[i], a[i], 1);
        }
    } else if (s == 2) {
        setHintLen(20);
        int spec = 0;
        if (n == 2)
            spec = 1;
        else {
            if (a[1] == a[2])
                spec = a[1];
            if (b[1] == b[2])
                spec = b[1];
            if (a[1] == b[2])
                spec = a[1];
            if (b[1] == a[2])
                spec = b[1];
        }

        forb(i,1, n+1) {
            forn(j, 10) {
                if (spec&(1<<j))
                    setHint(i,j+1,1);
            }
        }
    } else if (s == 3) {

    }


}

vi p;
void dfs1(int x, int n)
{
    forb(i,1,n+1) {
        if (x == i) continue;
        if (i == p[x]) continue;

        if (getHint(i)) {
            p[i] = x;
            goTo(i);
            dfs1(i,n);
            goTo(x);
        }

    }
}

void
speedrun(int s, int n, int x) {
    if (s == 1) {
        p.assign(n+1, -1);
        dfs1(x,n);
    } else if (s == 2) {
        int spec = 0;

        forn(j, 10) {
            if (getHint(j+1))
                spec |= 1<<j;
        }

        goTo(spec);

        forb(i, 1, n+1) {
            goTo(i);
            goTo(spec);
        }
    }
}


#ifdef ONPC
int lg;
int cur;
vector<bool> vis;
int cnt = 0;
int mist = 0;;
const int N = 1000;
int a[N+1], b[N+1];
vector<vector<bool>> h;
void setHintLen(int l){
    lg = l;
    forn(i, sz(h))
        h[i].assign(l,0);
}

void setHint(int i, int j, bool b) {
    --i, --j;
    assert(i < sz(h));
    assert(j < lg);
    h[i][j] = b;
}

int getLength() {
    return lg;
}
bool getHint(int j) {
    j--;
    assert(j < lg);
    return h[cur][j];
}
bool goTo(int x) {
    for(int i = 1; i < sz(h); ++i) {
        if (a[i] == cur+1 && b[i] == x
         || b[i] == cur+1 && a[i] == x ) {
            cur = x - 1;
            if (vis[cur] == 0) {
                vis[cur] = 1;
                ++cnt;
            }
            return 1;
        }
    }
    ++mist;
    return 0;
}



int32_t
main(int argc, char *argv[])
{
    if (argc > 1)
        freopen(argv[1], "r", stdin);
    ios_base::sync_with_stdio(0); cin.tie(0);
    int sub, n, st;

    cin >> sub >> n >> st;

    h.assign(n,{});
    vis.assign(n,0);

    vis[st-1] = 1;
    cnt = 1;

    for (int i = 1; i < n; ++i) {
        cin >> a[i] >> b[i];
    }

    assignHints(sub, n, a, b);
    speedrun(sub, n, st);

    cout << cnt << ' ' << mist;
}
#endif
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 808 KB Output is correct
2 Correct 33 ms 800 KB Output is correct
3 Correct 34 ms 756 KB Output is correct
4 Correct 37 ms 924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 736 KB Output is correct
2 Correct 30 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 208 KB setHintLen was never called
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 208 KB setHintLen was never called
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 208 KB setHintLen was never called
2 Halted 0 ms 0 KB -