QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#399855 | #370. City | bashkort# | 0 | 64ms | 6116kb | C++20 | 4.3kb | 2024-04-26 18:35:01 | 2024-07-04 03:38:33 |
Judging History
Encoder
#include "Encoder.h"
#include <bits/stdc++.h>
using namespace std;
void Encode(int n, int U[], int V[]) {
vector<vector<int>> adj(n);
for (int i = 0; i < n - 1; ++i) {
adj[U[i]].push_back(V[i]);
adj[V[i]].push_back(U[i]);
}
constexpr int B = 30;
constexpr int A0 = 6, A1 = 14;
vector<int> code(n), siz(n), type(n), father(n), tin(n), tout(n);
vector<vector<int>> g(n);
auto dfs = [&](auto self, int v) -> void {
siz[v] = 1;
vector<int> nxt;
for (int to : adj[v]) {
adj[to].erase(std::find(adj[to].begin(), adj[to].end(), v));
self(self, to);
siz[v] += siz[to];
}
type[v] = siz[v] >= B;
for (int to : adj[v]) {
if (siz[to] < B && type[v] == 1) {
nxt.push_back(to);
} else {
g[v].push_back(to);
}
}
if (type[v] == 0) {
return;
}
vector<int> stk;
int sum_stk = 0;
for (int x : nxt) {
stk.push_back(x);
sum_stk += siz[x];
if (sum_stk >= B) {
int new_vertex = size(tin);
g.push_back(stk);
g[v].push_back(new_vertex);
tin.push_back({}), tout.push_back({});
type.push_back(1);
stk.clear();
sum_stk = 0;
}
}
g[v].insert(g[v].end(), stk.begin(), stk.end());
sum_stk = 0;
};
dfs(dfs, 0);
int cnt[2]{};
auto gfs = [&](auto self, int v, int last) -> void {
tin[v] = cnt[type[v]];
cnt[type[v]] += 1;
if (type[v] == 1) {
for (int to : g[v]) {
if (type[to] == 1) {
self(self, to, v);
}
}
cnt[0] = 0;
for (int to : g[v]) {
if (type[to] == 0) {
self(self, to, v);
}
}
} else {
father[v] = last;
for (int to : g[v]) {
self(self, to, last);
}
}
tout[v] = cnt[type[v]];
};
gfs(gfs, 0, 0);
int mx = 0;
for (int i = 0; i < g.size(); ++i) {
if (type[i] == 1) {
mx = max(mx, tout[i]);
}
}
if ((1 << A1) <= mx) {
return;
}
assert((1 << A1) > mx);
for (int v = 0; v < n; ++v) {
if (type[v] == 1) {
code[v] = ((((tout[v] - tin[v]) << A1) + tin[v]) << 1) + 1;
} else {
code[v] = (((((tin[father[v]] << A0) + tout[v] - tin[v]) << A0) + tin[v]) << 1) + 0;
}
// if (v == 3 || v == 21) {
// cout << v << ":\n";
// cout << tin[v] << " " << tout[v] << " " << type[v] << " " << siz[v] << " " << father[v] << endl;
// }
// cerr << code[v] << " \n"[v == n - 1];
}
for (int i = 0; i < n; ++i) {
Code(i, code[i]);
}
}
Device
#include "Device.h"
#include <bits/stdc++.h>
using namespace std;
constexpr int B = 30;
constexpr int A0 = 7, A1 = 14;
array<int, 3> query(long long S) {
if (S % 2 == 0) {
S /= 2;
int tin = S & ((1 << A0) - 1);
int tout = tin + ((S >> A0) & ((1 << A0) - 1));
int father = (S >> (2 * A0));
return {tin, tout, father};
} else {
S /= 2;
int tin = S & ((1 << A1) - 1);
int tout = tin + ((S >> A1) & ((1 << A1) - 1));
return {tin, tout, -1};
}
}
void InitDevice() {
}
int Answer(long long S, long long T) {
auto a = query(S);
auto b = query(T);
if (S % 2 == T % 2) {
if (S % 2 == 0 && a[2] != b[2]) {
return 2;
}
if (a[0] <= b[0] && a[1] >= b[1]) {
return 1;
} else if (b[0] <= a[0] && b[1] >= a[1]) {
return 0;
} else {
return 2;
}
} else {
if (S % 2 == 0) {
if (b[0] <= a[2] && b[1] > a[2]) {
return 0;
} else {
return 2;
}
} else {
if (a[0] <= b[2] && a[1] > b[2]) {
return 1;
} else {
return 2;
}
}
}
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3808kb
input:
10 45 0 5 0 2 4 3 6 4 0 6 2 8 6 9 2 1 5 7 5 0 0 2 8 0 0 7 0 6 1 0 4 0 0 3 0 9 5 2 5 8 7 5 5 6 1 5 4 5 5 3 9 5 8 2 7 2 2 6 2 1 2 4 3 2 2 9 7 8 6 8 8 1 8 4 3 8 9 8 6 7 1 7 4 7 3 7 9 7 1 6 6 4 6 3 6 9 4 1 1 3 9 1 3 4 9 4 9 3
output:
1280 138 390 144 270 258 524 132 136 146
input:
Interaction has been finished!
output:
0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 1280
result:
wrong answer Wrong Answer [6] (Query #2 returned 2 but expected 1)
Subtask #2:
score: 0
Wrong Answer
Test #13:
score: 0
Wrong Answer
time: 64ms
memory: 6116kb
input:
700 244650 407 643 680 336 573 208 466 455 159 648 575 549 50 567 251 211 211 481 530 513 136 334 112 492 175 396 643 483 265 132 20 160 174 550 251 90 99 236 579 374 670 613 495 379 251 170 652 61 495 467 27 317 202 484 420 592 542 354 565 650 35 88 216 681 277 219 299 171 220 647 418 433 434 660 2...
output:
1179649 205078 262284 106634 287024 172490 278812 221328 229586 278732 262596 204956 147622 41256 286904 262424 172202 286994 286868 90296 229954 240514 131224 172242 229564 229550 73860 41366 49284 278716 90436 262334 287138 262318 286986 175360 123068 65674 229612 41116 222090 147640 106632 172312...
input:
Interaction has been finished!
output:
0 0 0 0 1 0 1 1 1 1 0 0 1 0 1 1 1 0 1 1 1 1 0 1 1 0 1 0 0 1 1 1 0 1 1 1 1 1 1 0 1 0 0 0 0 1 1 0 0 1 1 0 1 1 0 0 0 1 1 0 0 1 0 0 1 0 0 0 1 1 1 1 0 1 0 1 1 1 0 1 1 1 1 0 0 0 1 1 0 0 1 0 1 1 0 1 0 0 1 0 0 1 1 0 1 1 1 1 0 1 1 1 1 1 1 0 1 1 0 0 1 0 0 1 0 1 0 0 0 1 0 0 1 0 1 1 1 1 1 0 1 0 0 0 1 0 0 0 0 1 ...
result:
wrong answer Wrong Answer [6] (Query #701 returned 2 but expected 0)