Submission #107129

# Submission time Handle Problem Language Result Execution time Memory
107129 2019-04-22T06:29:24 Z szawinis Amusement Park (JOI17_amusement_park) C++17
0 / 100
38 ms 4436 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);
    }
//    cerr << u << ' ' << pre[u] << endl;
}

int get_lca(int u, int v, vector<int> &d, vector<int> &par) {
    if(d[u] < d[v]) swap(u, v);
    while(d[u] > d[v]) u = par[u];
    while(u != v) {
        u = par[u];
        v = par[v];
    }
    return u;
}

long long moveToNext(int u, int v, vector<int> &d, vector<int> &par) {
    int org_u = u, org_v = v;
    int lca = get_lca(u, v, d, par);
//    cerr << "Ioi_moveToNext " << u <<' ' << v << ' ' << lca << endl;
    vector<int> ord1, ord2;
    while(u != lca) {
        ord1.push_back(u);
        u = par[u];
    }
    while(v != lca) {
        ord2.push_back(v);
        v = par[v];
    }


    vector<int> ord = ord1;
    ord.push_back(lca);
    for(int i = ord2.size() - 1; i >= 0; i--) ord.push_back(ord2[i]);
    ord.erase(ord.begin());

    assert(ord.back() == org_v);

//    for(int x: ord) cerr << x << ' ';
//    cerr << endl;

    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;
    }
//    for(int i = 0; i < n; i++) {
//        cerr << "Ioi_rev " << i << ' ' << rev[i] << endl;
//    }

    long long ret = V << pre[P] % 60;
    int curr = P;
    for(int step = 1; step < 61; step++) {
        int pos = (pre[P] + step) % 60;
        int nxt = rev[pre[P] + step < n ? pre[P] + step : (pre[P] + step) % 60];
        assert(0 <= curr && curr < n && 0 <= nxt && nxt < n && curr != nxt);
//        cerr << "Ioi_iterate " << nxt << ' ' << pre[nxt] % 60 << endl;
        ret += moveToNext(curr, nxt, d, par) << pos;
        curr = nxt;
    }
    return ret;
}

Compilation message

Ioi.cpp: In function 'long long int moveToNext(int, int, std::vector<int>&, std::vector<int>&)':
Ioi.cpp:28:9: warning: unused variable 'org_u' [-Wunused-variable]
     int org_u = u, org_v = v;
         ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 872 KB Output is correct
2 Correct 4 ms 776 KB Output is correct
3 Correct 5 ms 900 KB Output is correct
4 Incorrect 5 ms 768 KB Wrong Answer [7]
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 4200 KB Output is correct
2 Correct 28 ms 4416 KB Output is correct
3 Incorrect 38 ms 4436 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 896 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 4200 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 4200 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -