QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#305370 | #6335. Belt Conveyor | danielkou5855 | 11 | 61ms | 30232kb | C++17 | 3.3kb | 2024-01-15 09:17:53 | 2024-01-15 09:17:53 |
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 - 1, 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);
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 1
Accepted
Test #1:
score: 1
Accepted
time: 0ms
memory: 4076kb
input:
random1 2 0 1 1 0xC321A02965AC2640
output:
Accepted: 1
result:
ok correct
Test #2:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
random1 2 1 0 0 0x8A99AD9552B2C218
output:
Accepted: 1
result:
ok correct
Test #3:
score: 0
Accepted
time: 0ms
memory: 3868kb
input:
random1 2 1 0 1 0x024D21FA307D148D
output:
Accepted: 1
result:
ok correct
Test #4:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
random1 2 0 1 0 0x3C96AB23CEB63F75
output:
Accepted: 1
result:
ok correct
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #5:
score: 0
Wrong Answer
time: 0ms
memory: 4076kb
input:
priority 30 10 29 10 13 17 11 2 15 15 27 9 26 18 0 14 1 22 24 29 28 6 22 4 20 15 5 28 4 21 24 3 13 1 8 13 12 8 19 16 3 1 10 24 29 12 8 4 7 2 7 28 25 12 7 2 23 27 22 89058848 6377689 24189123 31671827 205117644 254374430 56016068 6819602 212866321 246625321 274047319 230485311 202854776 280075001 203...
output:
Wrong Answer [8]
result:
wrong answer Token "Wrong" doesn't correspond to pattern "Accepted:"
Subtask #3:
score: 10
Accepted
Test #11:
score: 10
Accepted
time: 51ms
memory: 29032kb
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:
Accepted: 4
result:
ok correct
Test #12:
score: 0
Accepted
time: 55ms
memory: 28920kb
input:
priority 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 ...
output:
Accepted: 4
result:
ok correct
Test #13:
score: 0
Accepted
time: 39ms
memory: 30232kb
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:
Accepted: 3
result:
ok correct
Test #14:
score: 0
Accepted
time: 61ms
memory: 29016kb
input:
priority 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 ...
output:
Accepted: 4
result:
ok correct
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%