QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#880035#3505. Flightsduongnc0000 13ms3840kbC++205.1kb2025-02-02 20:25:562025-02-02 20:25:56

Judging History

This is the latest submission verdict.

  • [2025-02-02 20:25:56]
  • Judged
  • Verdict: 0
  • Time: 13ms
  • Memory: 3840kb
  • [2025-02-02 20:25:56]
  • 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;
vector<bool> ig;
vector<vector<pair<int, int>>> g;
vector<vector<int>> group;
vector<pair<int, int>> lab;
vector<int> par; 

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

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

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 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);
    }

    ig.assign(N - 1, false);
    int root = -1;
    for (int i = 0; i < N; ++i) if (isz(g[i]) == 1) {
        root = i;
        break;
    }
    dfs1(0, -1);

    group.clear();
    par.assign(N, -1);
    lab.assign(N, {-1, -1});
    for (int i = 0; i < N; ++i) if (lab[i].first == -1) {
        group.emplace_back();
        get_group(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);
    // cout << vX << " " << vY << " " << len << endl;

    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];
	}

	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: 0
Wrong Answer

Test #1:

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

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: 1ms
memory: 3712kb

input:

1
3 2 0
111100001000

output:

00000000000000000000
2

input:


output:

2
12

result:

points 1.0 L = 12 (test case 1)

Test #3:

score: 15
Accepted
time: 2ms
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: 2ms
memory: 3840kb

input:

1
5 4 0
11110000100000000000

output:

00000000000000000000
1

input:


output:

1
20

result:

points 1.0 L = 20 (test case 1)

Test #5:

score: 0
Wrong Answer
time: 1ms
memory: 3840kb

input:

1
10000 6436 11363
1111111111111111111111111111000000000000000000000000010101010101010101010101010100000000000000000000000001011000000000

output:

10111111011101110001
51

input:


output:

51
118

result:

wrong answer Incorrect answer: read 51 but expected 28 (test case 1)

Subtask #2:

score: 0
Wrong Answer

Test #16:

score: 0
Wrong Answer
time: 13ms
memory: 3584kb

input:

15
2 0 1
11110000
3 2 0
111100000000
4 1 3
1111000010000000
5 4 1
11110000100001000100
10000 4635 14839
0010001000100010001000100010001000000000000000000000101010101010101010101010101000000000000000000000000000001000000000
10000 1916 2750
1100110011001100110011001100110011001100110011001100110011001...

output:

00000000000000000000
1
00000000000000000000
1
00000000000000000000
2
00000000000000000000
2
11110110111100110110
25
00100111010100001100
23
00011111011101101001
26
10101111011011110110
40
00010010011100110001
1880
10001010010100110010
47
00111110101000010110
59
00011110110110110010
68
01101000110001...

input:


output:

1
1
2
2
25
23
26
40
1880
47
59
68
173
9994
673
118

result:

wrong answer Incorrect answer: read 25 but expected 20 (test case 5)