Submission #257347

# Submission time Handle Problem Language Result Execution time Memory
257347 2020-08-04T06:41:39 Z imeimi2000 None (JOI16_snowy) C++17
100 / 100
21 ms 2052 KB
#include <bits/stdc++.h>

using namespace std;

void Save(int, int);

const static int mod = 12, lg = 9;
static int A[501], B[501], n;
static vector<int> edge[501];
static vector<int> D[mod];
static int par[501];

void dfs1(int x, int p, int d) {
    par[x] = p;
    if (d) D[d % mod].push_back(x);
    for (int i : edge[x]) {
        if (i == p) continue;
        dfs1(i, x, d + 1);
    }
}

void InitAnya(int _n, int _A[], int _B[]) {
    n = _n;
    for (int i = 1; i < n; ++i) {
        A[i] = _A[i - 1] + 1;
        B[i] = _B[i - 1] + 1;
        edge[A[i]].push_back(B[i]);
        edge[B[i]].push_back(A[i]);
    }
    dfs1(1, 0, 0);
    for (int i = 1; i < n; ++i) {
        if (par[A[i]] == B[i]) swap(A[i], B[i]);
    }
    int mn = 0;
    for (int i = 1; i < mod; ++i) if (D[i].size() < D[mn].size()) mn = i;
    swap(D[0], D[mn]);
}

static int dist[501];
static int pdis[501];
void dfs2(int x, int p, int d) {
    dist[x] = d;
    for (int i : edge[x]) {
        if (i == p) continue;
        dfs2(i, x, d + pdis[i]);
    }
}

void Anya(int C[]) {
    for (int i = 1; i < n; ++i) {
        Save(i + n, pdis[B[i]] = C[i - 1]);
    }
    dfs2(1, 0, 0);
    for (int o = 0; o < int(D[0].size()); ++o) {
        int d = dist[D[0][o]];
        for (int i = 0; i < lg; ++i) {
            Save(o * lg + i, d & 1);
            d >>= 1;
        }
    }
}
#include <bits/stdc++.h>

using namespace std;

int Ask(int);

const static int mod = 12, lg = 9;
static int A[501], B[501], n;
static vector<int> edge[501];
static vector<int> D[mod];
static int par[501], pari[501];

void dfs1(int x, int p, int d) {
    par[x] = p;
    if (d) D[d % mod].push_back(x);
    for (int i : edge[x]) {
        if (i == p) continue;
        dfs1(i, x, d + 1);
    }
}

static int ord[501];
void InitBoris(int _n, int _A[], int _B[]) {
    n = _n;
    for (int i = 1; i < n; ++i) {
        A[i] = _A[i - 1] + 1;
        B[i] = _B[i - 1] + 1;
        edge[A[i]].push_back(B[i]);
        edge[B[i]].push_back(A[i]);
    }
    dfs1(1, 0, 0);
    for (int i = 1; i < n; ++i) {
        if (par[A[i]] == B[i]) swap(A[i], B[i]);
        pari[B[i]] = i;
    }
    int mn = 0;
    for (int i = 1; i < mod; ++i) if (D[i].size() < D[mn].size()) mn = i;
    swap(D[0], D[mn]);
    memset(ord, -1, sizeof(ord));
    for (int i = 0; i < int(D[0].size()); ++i) {
        ord[D[0][i]] = i;
    }
}

int Boris(int x) {
    ++x;
    int ret = 0;
    while (x > 1) {
        int o = ord[x];
        if (o < 0) {
            ret += Ask(pari[x] + n);
            x = par[x];
            continue;
        }
        int v = 0;
        for (int i = lg; i--; ) {
            v <<= 1;
            v |= Ask(o * lg + i);
        }
        return ret + v;
    }
    return ret;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 996 KB Output is correct
2 Correct 2 ms 788 KB Output is correct
3 Correct 3 ms 1024 KB Output is correct
4 Correct 4 ms 1024 KB Output is correct
5 Correct 6 ms 1280 KB Output is correct
6 Correct 7 ms 1444 KB Output is correct
7 Correct 6 ms 1280 KB Output is correct
8 Correct 8 ms 1436 KB Output is correct
9 Correct 9 ms 1280 KB Output is correct
10 Correct 9 ms 1440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1428 KB Output is correct
2 Correct 11 ms 1356 KB Output is correct
3 Correct 8 ms 1280 KB Output is correct
4 Correct 8 ms 1432 KB Output is correct
5 Correct 8 ms 1280 KB Output is correct
6 Correct 8 ms 1428 KB Output is correct
7 Correct 7 ms 1428 KB Output is correct
8 Correct 8 ms 1364 KB Output is correct
9 Correct 10 ms 1428 KB Output is correct
10 Correct 8 ms 1280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1916 KB Output is correct
2 Correct 15 ms 1812 KB Output is correct
3 Correct 16 ms 1904 KB Output is correct
4 Correct 15 ms 1792 KB Output is correct
5 Correct 15 ms 1744 KB Output is correct
6 Correct 16 ms 1792 KB Output is correct
7 Correct 15 ms 1904 KB Output is correct
8 Correct 15 ms 1792 KB Output is correct
9 Correct 15 ms 1904 KB Output is correct
10 Correct 15 ms 1908 KB Output is correct
11 Correct 15 ms 1792 KB Output is correct
12 Correct 16 ms 1900 KB Output is correct
13 Correct 16 ms 2020 KB Output is correct
14 Correct 15 ms 1792 KB Output is correct
15 Correct 16 ms 1896 KB Output is correct
16 Correct 16 ms 1792 KB Output is correct
17 Correct 15 ms 1908 KB Output is correct
18 Correct 15 ms 1792 KB Output is correct
19 Correct 15 ms 1812 KB Output is correct
20 Correct 16 ms 1792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 1536 KB Output is correct
2 Correct 21 ms 1796 KB Output is correct
3 Correct 17 ms 1900 KB Output is correct
4 Correct 16 ms 1856 KB Output is correct
5 Correct 18 ms 1904 KB Output is correct
6 Correct 15 ms 1792 KB Output is correct
7 Correct 17 ms 1924 KB Output is correct
8 Correct 15 ms 1928 KB Output is correct
9 Correct 16 ms 1848 KB Output is correct
10 Correct 15 ms 1924 KB Output is correct
11 Correct 16 ms 1916 KB Output is correct
12 Correct 16 ms 1792 KB Output is correct
13 Correct 16 ms 1912 KB Output is correct
14 Correct 16 ms 1792 KB Output is correct
15 Correct 17 ms 1908 KB Output is correct
16 Correct 16 ms 1792 KB Output is correct
17 Correct 16 ms 1848 KB Output is correct
18 Correct 17 ms 1920 KB Output is correct
19 Correct 17 ms 1912 KB Output is correct
20 Correct 17 ms 1916 KB Output is correct
21 Correct 17 ms 1920 KB Output is correct
22 Correct 17 ms 1912 KB Output is correct
23 Correct 17 ms 1844 KB Output is correct
24 Correct 16 ms 1792 KB Output is correct
25 Correct 17 ms 1880 KB Output is correct
26 Correct 21 ms 1844 KB Output is correct
27 Correct 20 ms 1844 KB Output is correct
28 Correct 19 ms 1912 KB Output is correct
29 Correct 16 ms 1924 KB Output is correct
30 Correct 16 ms 1904 KB Output is correct
31 Correct 17 ms 1792 KB Output is correct
32 Correct 16 ms 1792 KB Output is correct
33 Correct 17 ms 1984 KB Output is correct
34 Correct 15 ms 1928 KB Output is correct
35 Correct 15 ms 1792 KB Output is correct
36 Correct 16 ms 1792 KB Output is correct
37 Correct 16 ms 1840 KB Output is correct
38 Correct 17 ms 1912 KB Output is correct
39 Correct 15 ms 1932 KB Output is correct
40 Correct 15 ms 1792 KB Output is correct
41 Correct 15 ms 2052 KB Output is correct
42 Correct 15 ms 1936 KB Output is correct
43 Correct 15 ms 1924 KB Output is correct
44 Correct 16 ms 1792 KB Output is correct
45 Correct 15 ms 1920 KB Output is correct
46 Correct 14 ms 1924 KB Output is correct
47 Correct 15 ms 1792 KB Output is correct
48 Correct 14 ms 1924 KB Output is correct
49 Correct 16 ms 1792 KB Output is correct
50 Correct 14 ms 1920 KB Output is correct