QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#305369 | #6335. Belt Conveyor | danielkou5855 | 0 | 49ms | 28912kb | C++17 | 3.3kb | 2024-01-15 09:17:17 | 2024-01-15 09:17:17 |
Judging History
answer
// Source: https://usaco.guide/general/io
#include "conveyor.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <bitset>
// #define int long long
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
using namespace std;
const int inf = (int) 1e9;
vector<vector<pair<int, int>>> adj;
vector<int> idx, parent, edge_idx;
void dfs(int c, int p, int e) {
parent[c] = p;
edge_idx[c] = e;
for (auto n : adj[c]) {
if (n.first != p) {
idx[n.first] = (idx[c] + 1) % 3;
dfs(n.first, c, n.second);
}
}
}
pair<int, int> combine(const pair<int, int> &a, const pair<int, int> b) {
if (b.first > a.first) {
return b;
}
return a;
}
void Solve(int N, vector<int> arr, vector<int> brr) {
adj.resize(N); idx.resize(N); parent.resize(N); edge_idx.resize(N);
for (int i = 0; i < N - 1; i++) {
adj[arr[i]].push_back({brr[i], i});
adj[brr[i]].push_back({arr[i], i});
}
for (int i = 0; i < N; i++) {
// start from leaf
if (sz(adj[i]) == 1) {
dfs(i, -1, -1); break;
}
}
vector<int> ans(N, inf); // inf means don't know
while (true) {
vector<int> ct(3, 0);
pair<int, int> best = {0, 0};
for (int i = 0; i < N; i++) {
int tmp = 0;
for (auto n : adj[i]) {
tmp |= (ans[n.second] == inf);
}
ct[idx[i]] += tmp;
best = combine(best, make_pair(ct[idx[i]], idx[i]));
}
// query
vector<int> xrr(N - 1, 0), yrr(N, 0);
for (int i = 0; i < N; i++) {
if (idx[i] == best.second) {
yrr[i] = 1;
}
}
for (int i = 0; i < N; i++) {
if (yrr[i]) {
for (auto n : adj[i]) {
if (ans[n.second] == 0 && arr[n.second] == i) {
xrr[n.second] = 1;
}
if (ans[n.second] == 1 && brr[n.second] == i) {
xrr[n.second] = 1;
}
}
}
}
vector<int> query = Query(xrr, yrr);
for (int i = 0; i < N; i++) {
if (!yrr[i]) {
continue;
}
if (query[i]) {
for (auto n : adj[i]) {
if (xrr[n.second]) { // reversed
if (n.first == brr[n.second]) {
// a -> b reversed (b -> a) doesn't work
ans[n.second] = 0;
} else {
// b -> a reversed (a -> b) doesn't work
ans[n.second] = 1;
}
} else {
// not reversed
if (n.first == brr[n.second]) {
// a -> b normal doesn't work
ans[n.second] = 1;
} else {
// b -> a normal doesn't work
ans[n.second] = 0;
}
}
}
} else {
for (auto n : adj[i]) {
if (query[n.first]) {
if (xrr[n.second]) { // reversed
if (n.first == brr[n.second]) {
// a -> b reversed (b -> a) works
ans[n.second] = 1;
} else {
// b -> a reversed (a -> b) works
ans[n.second] = 0;
}
} else { // not reversed
if (n.first == brr[n.second]) {
// a -> b normal works
ans[n.second] = 0;
} else {
// b -> a normal works
ans[n.second] = 1;
}
}
}
}
}
}
bool good = true;
for (int i = 0; i < N - 1; i++) {
if (ans[i] == inf) {
good = false; break;
}
}
if (good) {
break;
}
}
Answer(ans);
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3692kb
input:
random1 2 0 1 1 0xC321A02965AC2640
output:
Wrong Answer [6]
result:
wrong answer Token "Wrong" doesn't correspond to pattern "Accepted:"
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #11:
score: 0
Wrong Answer
time: 49ms
memory: 28912kb
input:
random1 100000 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 9...
output:
Wrong Answer [6]
result:
wrong answer Token "Wrong" doesn't correspond to pattern "Accepted:"
Subtask #4:
score: 0
Skipped
Dependency #1:
0%