답안 #107108

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
107108 2019-04-22T02:27:36 Z szawinis Amusement Park (JOI17_amusement_park) C++17
0 / 100
33 ms 4768 KB
#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4+1;

void dfs(int u, vector<vector<int> > &g, vector<int> &pre, int &tick) {
    pre[u] = ++tick;
    for(int v: g[u]) {
        if(pre[v]) continue;
        dfs(v, g, pre, tick);
    }
}

void Joi(int n, int m, int A[], int B[], long long X, int T) {
    vector<vector<int> > g(n + 1);
    vector<int> pre(n + 1);
    int tick = 0;
    for(int i = 0; i < m; i++) {
        g[A[i]].push_back(B[i]);
        g[B[i]].push_back(A[i]);
    }
    dfs(0, g, pre, tick);
    for(int i = 0; i < n; i++) {
        MessageBoard(i, X >> ((pre[i] - 1) % 60) & 1);
    }
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4+1;

void dfs(int u, vector<vector<int> > &g, vector<int> &d, vector<int> &par, vector<int> &pre, vector<int>& rev, int &tick) {
    pre[u] = ++tick;
    for(int v: g[u]) {
        if(pre[v]) continue;
        d[v] = d[u] + 1;
        par[v] = u;
        dfs(v, g, d, par, pre, rev, tick);
    }
}

int moveToNext(int u, int v, vector<int>& d, vector<int>& par) {
    vector<int> ord1, ord2;
    while(d[u] > d[v]) ord1.push_back(par[u]), u = par[u];
    while(d[v] > d[u]) ord2.push_back(v), v = par[v];
    vector<int> ord = ord1;
    for(int i = ord2.size() - 1; i >= 0; i--) ord.push_back(ord2[i]);
    int ret = -1;
    for(int x: ord) ret = Move(x);
    return ret;
}

long long Ioi(int n, int m, int A[], int B[], int P, int V, int T) {

    vector<vector<int> > g(n + 1);
    vector<int> d(n + 1), par(n + 1), pre(n + 1), rev(n + 1);
    int tick = 0;

    for(int i = 0; i < m; i++) {
        g[A[i]].push_back(B[i]);
        g[B[i]].push_back(A[i]);
    }

    dfs(0, g, d, par, pre, rev, tick);
    for(int i = 0; i < n; i++) {
        --pre[i];
        rev[pre[i]] = i;
//        cerr << "Ioi_pre " << i << ' ' << pre[i] << endl;
    }

    long long ret = V << pre[P] % 60;
    int curr = P;
    for(int step = 1; step < 60; step++) {
        int pos = (pre[curr] + 1) % 60;
        int nxt = rev[pre[curr] + 1];
//        cerr << "Ioi_iterate " << curr << ' ' << nxt << ' ' << pos << endl;
        ret += moveToNext(curr, nxt, d, par) << pos;
        curr = nxt;
    }
    return ret;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 988 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 31 ms 4656 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 932 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 33 ms 4768 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 31 ms 4740 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -