QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#882322#3505. Flightsduongnc00015 46ms3840kbC++208.3kb2025-02-04 23:55:022025-02-04 23:55:03

Judging History

This is the latest submission verdict.

  • [2025-02-04 23:55:03]
  • Judged
  • Verdict: 15
  • Time: 46ms
  • Memory: 3840kb
  • [2025-02-04 23:55:02]
  • Submitted

Ali

#include "Ali.h"
#include <bits/stdc++.h>
#define taskname ""
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define i64 long long
#define isz(x) (int)x.size()
using namespace std;

namespace {

int N, nn;
vector<bool> ig;
vector<vector<pair<int, int>>> g;
vector<vector<int>> group;
vector<pair<int, int>> lab;
vector<int> par, dep, sz, lst;

vector<string> six = {
    "000011001111",
    "000010110111",
    "000001110111",
    "000000111111",
    "000001011111",
    "000011100111",
    "000101100111",
    "000011011011",
    "000001111011",
    "000001101111",
    "000010111011",
};

int dfs1(int u, int p) {
    int sz = 1;
    for (auto [v, id] : g[u]) if (v != p) {
        dep[v] = dep[u] + 1;
        int val = dfs1(v, u);
        if (val >= 7) ig[id] = true;
        else sz += val;
    }
    return sz;
}

void get_group(int u, int p) {
    sz[u] = 1;
    lab[u] = {isz(group) - 1, isz(group.back())};
    group.back().emplace_back(u);
    for (auto [v, id] : g[u]) if (v != p and id < N - 1 and not ig[id]) {
        par[v] = lab[u].second;
        get_group(v, u);
        sz[u] += sz[v];
        lst[u] = lst[v];
    }
    if (lst[u] == -1) lst[u] = u;
}

void add_nodes(int u) {
    int cnt = 0;
    for (auto [v, id] : g[u]) if (not ig[id]) {
        ++cnt;
        int clst = lst[v];
        while (sz[v] < 6) {
            g.emplace_back();
            ig.emplace_back(0);
            g[clst].emplace_back(nn, nn - 1);
            g[nn].emplace_back(clst, nn - 1);
            clst = nn, sz[v]++, nn++;
        }
    }
    while (cnt < 2) {
        int clst = u;
        for (int i = 0; i < 6; ++i) {
            g.emplace_back();
            ig.emplace_back(0);
            g[clst].emplace_back(nn, nn - 1);
            g[nn].emplace_back(clst, nn - 1);
            clst = nn, nn++;
        }
        ++cnt;
    }
}

int get_centroid() {
    vector<int> sz(N);
    auto dfs_sz = [&](auto self, int u, int p) -> void {
        sz[u] = 1;
        for (auto [v, id] : g[u]) if (v != p) {
            self(self, v, u);
            sz[u] += sz[v];
        }
    };
    dfs_sz(dfs_sz, 0, -1);
    auto dfs_cen = [&](auto self, int u, int p) -> int {
        for (auto [v, id] : g[u]) if (v != p) {
            if (sz[v] > sz[0] / 2) return self(self, v, u);
        }
        return u;
    };
    int root = dfs_cen(dfs_cen, 0, -1);
    queue<int> q;
    vector<int> vis(N);
    q.emplace(root);
    vis[root] = true;
    while (not q.empty()) {
        int u = q.front();
        if (isz(g[u]) < 3) {
            root = u;
            break;
        }
        q.pop();
        for (auto [v, id] : g[u]) if (not vis[v]) {
            q.emplace(v);
            vis[v] = true;
        }
    }
    vis.assign(N, -1);
    q = queue<int>();
    vis[root] = 0;
    q.emplace(root);
    while (not q.empty()) {
        int u = q.front();
        q.pop();
        for (auto [v, id] : g[u]) if (vis[v] == -1) {
            vis[v] = vis[u] + 1;
            q.emplace(v);
        }
    }
    assert(*max_element(all(vis)) <= 5000);
    return root;
}

int callitacheck(int u, int p) {
    int sz = 1;
    for (auto [v, id] : g[u]) if (v != p and not ig[id]) {
        int val = callitacheck(v, u);
        if (p == -1) assert(val == 6);
        sz += val;
    }
    if (p == -1) assert(sz == 13);
    return sz;
}

string get_hash(int u, int p) {
    vector<string> vec;
    for (auto [v, id] : g[u]) if (v != p and not ig[id]) {
        vec.push_back(get_hash(v, u));
    }
    sort(all(vec));
    string res = "";
    res.push_back('0');
    for (auto s : vec) res += s;
    res.push_back('1');
    return res;
};

array<int, 3> bfs(int gX, int gY) {
    queue<int> q;
    vector<int> trace(N, -1), d(N, -1);
    d[group[gX][0]] = 0;
    q.emplace(group[gX][0]);
    while (not q.empty()) {
        auto u = q.front(); q.pop();

        if (lab[u].first == gY) {
            int len = 0, ou = u;
            while (lab[u].first != gX) {
                u = trace[u];
                ++len;
            }
            return {u, ou, len};
        }

        for (auto [v, id] : g[u]) {
            if (d[v] == -1) {
                d[v] = d[u] + 1;
                trace[v] = u;
                q.emplace(v);
            }
        }
    }
}

void dfs2(int u, int p, int d) {
    lab[u].first = d;
    for (auto [v, id] : g[u]) if (v != p and id < N - 1 and not ig[id]) {
        dfs2(v, u, d + 1);
    }
}

}

void Init(int N, vector<int> U, vector<int> V) {
    ::N = N;
    g.assign(N, {});
    for (int i = 0; i < N - 1; ++i) {
        int u = U[i], v = V[i];
        g[u].emplace_back(v, i);
        g[v].emplace_back(u, i);
    }

    dep.assign(N, 0);
    ig.assign(N - 1, false);
    int root = get_centroid();
    dfs1(root, -1);

    nn = N;
    vector<int> avec(N);
    iota(all(avec), 0);
    sort(all(avec), [&](int x, int y) {
        return dep[x] < dep[y];
    });
    group.clear();
    sz.assign(N, 0);
    lst.assign(N, -1);
    par.assign(N, -1);
    lab.assign(N, {-1, -1});
    for (int i : avec) if (lab[i].first == -1) {
        group.emplace_back();
        get_group(i, -1);
        add_nodes(i);
        // get_hash(i, -1);
        // callitacheck(i, -1);
    }

    for (int i = 0; i < N; ++i) {
        // cout << i << " " << lab[i].first * 13 + lab[i].second << endl;
        SetID(i, lab[i].first * 13 + lab[i].second);
    }
}

string SendA(string S) {
    int val = 0, cnt = 0;
    for (int i = 0; i < 20; ++i) {
        val += (S[i] - '0') << i;
    }
    int gX = -1, gY = -1;
    for (int i = 0; i < 1429; ++i) for (int j = i; j < 1429; ++j) {
        if (val == cnt) gX = i, gY = j;
        ++cnt;
    }

    if (gX == gY) {
        string res = "";
        for (auto u : group[gX]) for (int i = 0; i < 4; ++i) {
            res.push_back((par[u] >> i & 1) + '0');
        }
        return res;
    }

    auto [vX, vY, len] = bfs(gX, gY);
    dfs2(vX, -1, 0); dfs2(vY, -1, 0);

    string res = "";

    sort(all(group[gX]), [&](const auto &lhs, const auto &rhs) {
        return lab[lhs].second < lab[rhs].second;
    });
    for (auto u : group[gX]) for (int i = 0; i < 4; ++i) {
        res.push_back((lab[u].first >> i & 1) + '0');
    }
    while (isz(res) < 52) res.push_back('0');

    sort(all(group[gY]), [&](const auto &lhs, const auto &rhs) {
        return lab[lhs].second < lab[rhs].second;
    });
    for (auto u : group[gY]) for (int i = 0; i < 4; ++i) {
        res.push_back((lab[u].first >> i & 1) + '0');
    }
    while (isz(res) < 104) res.push_back('0');

    for (int i = 0; i < 14; ++i) {
        res.push_back((len >> i & 1) + '0');
    }

    return res;
}

Benjamin

#include "Benjamin.h"
#include <bits/stdc++.h>
#define taskname ""
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define i64 long long
#define isz(x) (int)x.size()
using namespace std;

namespace {

int gX, nX, gY, nY;

}

string SendB(int N, int X, int Y) {
	if (X > Y) swap(X, Y);

	gX = X / 13, nX = X % 13;
	gY = Y / 13, nY = Y % 13;

	int val = -1, cnt = 0;
	for (int i = 0; i < 1429; ++i) for (int j = i; j < 1429; ++j) {
		if (i == gX and j == gY) val = cnt;
		++cnt;
	}

	string res = "";
	for (int i = 0; i < 20; ++i) {
		res.push_back((val >> i & 1) + '0');
	}
	return res;
}

int Answer(string T) {
	int res = 0;

	if (gX == gY) {
		int N = isz(T) / 4;
		vector<vector<int>> g(N);
		for (int i = 1; i < N; ++i) {
			int p = 0;
			for (int j = 0; j < 4; ++j) {
				p += (T[i * 4 + j] - '0') << j;
			}
			g[p].emplace_back(i);
			g[i].emplace_back(p);
		}
		vector<int> d(N, -1);
		queue<int> q;
		d[nX] = 0;
		q.emplace(nX);
		while (not q.empty()) {
			auto u = q.front(); q.pop();
			for (auto v : g[u]) if (d[v] == -1) {
				d[v] = d[u] + 1;
				q.emplace(v);
			}
		}
		return d[nY];
	}

	// cout << gX << " " << gY << " " << nX << " " << nY << endl;

	for (int i = nX * 4; i < (nX + 1) * 4; ++i) {
		res += (T[i] - '0') << (i - nX * 4);
	}
	for (int i = 52 + nY * 4; i < 52 + (nY + 1) * 4; ++i) {
		res += (T[i] - '0') << (i - 52 - nY * 4);
	}
	for (int i = 104; i < 104 + 14; ++i) {
		res += (T[i] - '0') << (i - 104);
	}
	return res;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 15
Accepted

Test #1:

score: 15
Accepted
time: 1ms
memory: 3840kb

input:

1
2 1 0
11110000

output:

00000000000000000000
1

input:


output:

1
8

result:

points 1.0 L = 8 (test case 1)

Test #2:

score: 15
Accepted
time: 0ms
memory: 3840kb

input:

1
3 2 1
111100000000

output:

00000000000000000000
2

input:


output:

2
12

result:

points 1.0 L = 12 (test case 1)

Test #3:

score: 15
Accepted
time: 1ms
memory: 3840kb

input:

1
4 2 0
1111000000000100

output:

00000000000000000000
1

input:


output:

1
16

result:

points 1.0 L = 16 (test case 1)

Test #4:

score: 15
Accepted
time: 0ms
memory: 3712kb

input:

1
5 3 1
11110000100010000000

output:

00000000000000000000
1

input:


output:

1
20

result:

points 1.0 L = 20 (test case 1)

Test #5:

score: 15
Accepted
time: 1ms
memory: 3840kb

input:

1
10000 5370 14587
0000100001000100110010000100000000000000000000000000000010000100010011001100100000000000000000000000000001011000000000

output:

00001011111011011110
28

input:


output:

28
118

result:

points 1.0 L = 118 (test case 1)

Test #6:

score: 15
Accepted
time: 2ms
memory: 3840kb

input:

1
10000 11505 1628
0000100001001100010011001100000000000000000000000000000010000100010011001000010000000000000000000000000010001000000000

output:

11001110011110010100
20

input:


output:

20
118

result:

points 1.0 L = 118 (test case 1)

Test #7:

score: 15
Accepted
time: 2ms
memory: 3840kb

input:

1
10000 11648 10064
0000100001001100100001000100000000000000000000000000000010000100110011000010010010000100110011000000000011011000000000

output:

10010110000010100011
29

input:


output:

29
118

result:

points 1.0 L = 118 (test case 1)

Test #8:

score: 15
Accepted
time: 2ms
memory: 3712kb

input:

1
10000 12702 6917
0000100001001000010011000100000000000000000000000000000010000100100001001100110000000000000000000000000010111000000000

output:

11000101110011101001
31

input:


output:

31
118

result:

points 1.0 L = 118 (test case 1)

Test #9:

score: 15
Accepted
time: 0ms
memory: 3712kb

input:

1
10000 6025 7587
0010110000100100100000000100000000000000000000000000000010000100110000100010100001001100001011000000000011010111000000

output:

01010100111011100001
240

input:


output:

240
118

result:

points 1.0 L = 118 (test case 1)

Test #10:

score: 15
Accepted
time: 1ms
memory: 3840kb

input:

1
8191 11896 2164
0000100001000100100001000100000000000000000000000000000010000100010010000100010000000000000000000000000000101000000000

output:

00110000001101101100
23

input:


output:

23
118

result:

points 1.0 L = 118 (test case 1)

Test #11:

score: 15
Accepted
time: 1ms
memory: 3712kb

input:

1
9996 5854 4246
0000100001001100110001001000010011001100010000000000000010000100110011000100110010000100110011000100110000001100000000

output:

11010010101100100110
54

input:


output:

54
118

result:

points 1.0 L = 118 (test case 1)

Test #12:

score: 15
Accepted
time: 1ms
memory: 3840kb

input:

1
9996 7334 10259
0000100001001100110001001100100001001100010011000000000010000100110011000100110010000100110001001100000001000010000000

output:

11101111000001111001
70

input:


output:

70
118

result:

points 1.0 L = 118 (test case 1)

Test #13:

score: 15
Accepted
time: 1ms
memory: 3712kb

input:

1
10000 9663 9637
0000100001001100001010100110000000000000000000000000000010000100110000101010011000000000000000000000000000011010000000

output:

10001010100111111101
96

input:


output:

96
118

result:

points 1.0 L = 118 (test case 1)

Test #14:

score: 15
Accepted
time: 1ms
memory: 3712kb

input:

1
10000 18557 18570
0000100001001100001010100110000000000000000000000000000010000100110000101010011000000000000000000000000011000000111001

output:

10100100111010011111
9999

input:


output:

9999
118

result:

points 1.0 L = 118 (test case 1)

Test #15:

score: 15
Accepted
time: 1ms
memory: 3840kb

input:

1
9997 2754 5482
1000000010000100110000101010010011000010101001101110000010000100110000101010011010000100110000101010011010001011000000

output:

01101000001000100010
218

input:


output:

218
118

result:

points 1.0 L = 118 (test case 1)

Subtask #2:

score: 0
Interactor Runtime Error

Test #16:

score: 44.0626
Acceptable Answer
time: 13ms
memory: 3840kb

input:

15
2 0 1
11110000
3 2 0
111100000000
4 1 3
1111000010000000
5 4 0
11110000000001000100
10000 4843 4543
0000100010000100110011000100000000000000000000000000000010000100110011000100100001000000000000000000000000001000000000
10000 2631 7690
00001000010011000010101001101000010011001100001000100000100001...

output:

00000000000000000000
1
00000000000000000000
1
00000000000000000000
2
00000000000000000000
2
01000000111101010110
20
01010011100110000010
24
11000111000101001010
20
01101000000110010000
21
00000000111001000110
1866
00000000001011011011
20
01010001100100100010
50
10101000001010001110
62
10110011110100...

input:


output:

1
1
2
2
20
24
20
21
1866
20
50
62
172
9999
659
118

result:

points 0.51838307230 L = 118 (test case 15)

Test #17:

score: 44.0626
Acceptable Answer
time: 43ms
memory: 3840kb

input:

50
2 1 0
11110000
3 0 1
111100000000
4 0 3
1111000010000000
5 3 1
11110000100000001100
6 3 1
111100001000000011000010
7 4 2
1111000010000100010010000000
8 15 14
1111000010000000110000100010
9 15 14
11110000100010000000001010100010
10 19 15
11110000100001001000000010101010
11 14 16
111100001000100011...

output:

00000000000000000000
1
00000000000000000000
1
00000000000000000000
1
00000000000000000000
2
00000000000000000000
2
00000000000000000000
1
10101001101000000000
1
10101001101000000000
1
10101001101000000000
4
10101001101000000000
1
10000000000000000000
3
10000000000000000000
3
10101001101000000000
3
1...

input:


output:

1
1
1
2
2
1
1
1
4
1
3
3
3
6
8
3
3
7
5
8
4
2
4
5
4
6
1
4
3
3
2
6
2
3
4
8
6
1
9
11
3
1
9
1
4
7
4
1
5
7
118

result:

points 0.51838307230 L = 118 (test case 50)

Test #18:

score: 44.0626
Acceptable Answer
time: 44ms
memory: 3712kb

input:

50
10000 11030 5948
0000100001001100001001001000010001001100001000100000000010000100100001001100010000000000000000000000000010011000000000
10000 8078 1237
0000100001001100001010101100000000000000000000000000000010000100110011000010010000000000000000000000000010110000000000
10000 970 11846
0000100001...

output:

00000001100001100001
29
00010111010000000100
19
01010011101010011000
26
10101001111100100101
32
01011110000010000100
21
10001110000100110010
23
11101001011100011110
29
00101100001001110010
26
10110100001001100100
21
00100111110110000110
29
01000010111000100011
28
00100010111101101110
29
101000000100...

input:


output:

29
19
26
32
21
23
29
26
21
29
28
29
24
16
25
27
27
22
26
23
29
24
30
28
30
23
21
19
19
35
28
34
23
23
30
23
17
24
34
26
21
32
27
36
22
28
28
28
25
15
118

result:

points 0.51838307230 L = 118 (test case 50)

Test #19:

score: 44.0626
Acceptable Answer
time: 44ms
memory: 3840kb

input:

50
10000 13325 7748
0000100001000100110000101100100001001100000000000000000010000100110000100010110010000100110000000000000010101000000000
10000 8296 783
0000100010000100010011001100000000000000000000000000000010000100110011001000010011000000000000000000000011001000000000
10000 4644 9637
00001000010...

output:

11001111110100100101
21
00100010010100101000
23
11110000010010110110
29
11101111101000111000
18
01001110001010111101
29
10000110010101000110
25
10111101000010011101
30
10001011100001100010
25
10011011100010110110
27
00100101001010110100
26
00011111001001100001
27
01110001010111001100
25
111110110011...

input:


output:

21
23
29
18
29
25
30
25
27
26
27
25
38
21
24
35
34
37
22
23
30
27
26
25
27
39
29
25
26
33
18
25
20
30
20
32
28
29
20
20
25
15
35
28
25
20
20
15
28
30
118

result:

points 0.51838307230 L = 118 (test case 50)

Test #20:

score: 44.0626
Acceptable Answer
time: 46ms
memory: 3712kb

input:

50
10000 6268 10172
0000100001001100010010000100110000101100000000000000000010000100010011000010110010000100000000000000000010010000000000
10000 1328 694
0000100001001100100001001100010000000000000000000000000010000100110011000010001010000100110001000000000011110000000000
10000 9781 4610
00001000010...

output:

10100111011111010001
14
00010101010001001000
19
11100001101000110110
29
10100101100010110010
25
10001101000110110111
41
10101000010111101010
23
11111001101000101000
25
01100011010101001100
20
11001101000111110110
28
01101011010011110101
21
00111010101000000010
23
01001000000001101101
27
110101100111...

input:


output:

14
19
29
25
41
23
25
20
28
21
23
27
29
27
25
29
18
27
18
27
19
27
20
25
26
18
21
26
23
24
25
16
28
39
22
25
30
23
4
20
29
24
25
19
22
31
30
26
32
27
118

result:

points 0.51838307230 L = 118 (test case 50)

Test #21:

score: 44.0626
Acceptable Answer
time: 46ms
memory: 3840kb

input:

50
10000 12795 6129
0000100001001100001010100110000000000000000000000000000010000100110000101010011000000000000000000000000011111011110010
10000 12746 11572
0010110001001000000010001010011000000000000000000000000010000100110011000010101000000000000000000000000010111011000000
10000 11375 3796
1010011...

output:

11100011011010010001
5096
11100000111110101011
228
10100010010111011010
1178
11101000111101111011
422
11111110100100000100
1510
00001100111101110001
1743
01010010011000100111
2292
01001111000110110001
1293
01011010011111010010
137
00110010100010000110
244
00000110010111110000
562
0100110101011001100...

input:


output:

5096
228
1178
422
1510
1743
2292
1293
137
244
562
433
800
881
782
360
320
697
116
475
216
107
489
724
424
152
365
192
99
333
304
338
476
382
423
99
104
241
347
276
286
346
508
335
198
276
266
153
124
352
118

result:

points 0.51838307230 L = 118 (test case 50)

Test #22:

score: 44.0626
Acceptable Answer
time: 45ms
memory: 3840kb

input:

50
10000 586 11367
0000100001000100110010000100010011001100000000000000000010001000010011001100001010100000000000000000000000000001000000
10000 15215 10024
0000100001001100110010000100110000101010000000000000000010000100110000101010010010000100110000101100000000101110000000
10000 8233 2848
000010000...

output:

00001001010111110000
132
11010011100100100011
122
01101011010101100010
53
11011110110110110010
57
11101111000111000111
83
00110100000001010110
45
01101101010100010001
50
10001000001001101000
28
01110101100100111000
35
01000110111110101110
38
01000010010000001010
46
00001110101011001100
23
1011010001...

input:


output:

132
122
53
57
83
45
50
28
35
38
46
23
20
36
29
34
39
27
18
30
31
28
34
21
21
26
19
35
31
22
24
33
27
29
27
28
32
37
27
18
25
28
26
23
27
31
31
17
17
27
118

result:

points 0.51838307230 L = 118 (test case 50)

Test #23:

score: 44.0626
Acceptable Answer
time: 45ms
memory: 3840kb

input:

50
10000 7984 13523
1100001001001100100001000000100000000000000000000000000010001000010001001100110000100000000000000000000010001010110000
10000 9523 11481
0000100001001100001010000100110000000000000000000000000010000100110010000100110000100000000000000000000011110010011000
9996 10040 8086
100000001...

output:

10010111101000010101
853
10010001100001111101
1620
10001100011110010101
154
10001101100101101011
849
00110010000010101001
559
10011101101111011110
80
00110010010011110100
131
01111110011001011010
163
10000000000011110101
101
11001000110101011011
91
11000111010011001110
149
10010110100010001110
227
0...

input:


output:

853
1620
154
849
559
80
131
163
101
91
149
227
253
142
194
215
80
167
89
261
185
192
168
87
182
74
98
79
175
64
75
153
34
134
93
155
34
101
187
91
96
105
166
228
143
151
125
115
183
95
118

result:

points 0.51838307230 L = 118 (test case 50)

Test #24:

score: 0
Interactor Runtime Error

input:

50
10000 9243 13551
0000100001001100001010100110000000000000000000000000000010000100110000101010011000000000000000000000000001001111111010
10000 2863 14148
0110101000101100010010000000000000000000000000000000000010000100110000101010011000000000000000000000000010010111101000
9996 17075 12457
00001000...

output:

10010100000101011101
6135
01101010100011100010
1520
01101010011001111011
2649
01100111001101001110
920
01110001001111101101
1025
11100100100111101011
1280
01111111111101110110
652
11011011010100011000
397
11101011100000101110
457
11101111110011101101
521
00010011100100011100
379
00110000100110100111...

input:


output:


result: