QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#306881 | #6335. Belt Conveyor | training4usaco | 100 ✓ | 233ms | 32516kb | C++17 | 6.7kb | 2024-01-17 14:56:17 | 2024-01-17 14:56:17 |
Judging History
answer
#include <iostream>
#include <vector>
#include "conveyor.h"
using namespace std;
// #include <cstdio>
// #include <cstdlib>
// #include <random>
// #include <utility>
// #include <vector>
// namespace {
// const int INVALID_X_LENGTH = 1;
// const int INVALID_X_RANGE = 2;
// const int INVALID_Y_LENGTH = 3;
// const int INVALID_Y_RANGE = 4;
// const int QUERY_LIMIT_EXCEEDED = 5;
// const int INVALID_A_LENGTH = 6;
// const int INVALID_A_RANGE = 7;
// const int WRONG_A = 8;
// const int ANSWER_TWICE = 9;
// const int NO_ANSWER = 10;
// const int QUERY_LIMIT = 30;
// int N;
// std::vector<int> A, B, C;
// int query_count = 0;
// bool answered = false;
// void WrongAnswer(int code) {
// printf("Wrong Answer [%d]\n", code);
// exit(0);
// }
// std::mt19937 rng(0);
// int random_select(const std::vector<int> &v) {
// return v[std::uniform_int_distribution<int>(0, v.size() - 1)(rng)];
// }
// } // namespace
// std::vector<int> Query(std::vector<int> x, std::vector<int> y) {
// // cout << "querying: ";
// // for(auto val : y) cout << val << " "; cout << endl;
// if (int(x.size()) != N - 1) {
// WrongAnswer(INVALID_X_LENGTH);
// }
// for (int i = 0; i < N - 1; i++) {
// if (x[i] != 0 && x[i] != 1) {
// WrongAnswer(INVALID_X_RANGE);
// }
// }
// if (int(y.size()) != N) {
// WrongAnswer(INVALID_Y_LENGTH);
// }
// for (int i = 0; i < N; i++) {
// if (y[i] != 0 && y[i] != 1) {
// WrongAnswer(INVALID_Y_RANGE);
// }
// }
// query_count++;
// if (query_count > QUERY_LIMIT) {
// WrongAnswer(QUERY_LIMIT_EXCEEDED);
// }
// std::vector<int> z(N, 0);
// std::vector<std::vector<int>> t(N);
// for (int i = 0; i < N - 1; i++) {
// int a = A[i], b = B[i];
// if (x[i] ^ C[i]) {
// std::swap(a, b);
// }
// t[a].push_back(b);
// }
// for (int i = 0; i < N; i++) {
// if (y[i]) {
// if (t[i].empty()) {
// // cout << "stayed at node " << i << endl;
// z[i] = 1;
// } else {
// int nxt = random_select(t[i]);
// // cout << i << " to " << nxt << endl;
// z[nxt] = 1;
// }
// }
// }
// return z;
// }
// void Answer(std::vector<int> a) {
// if (answered) {
// WrongAnswer(ANSWER_TWICE);
// }
// answered = true;
// if (int(a.size()) != N - 1) {
// WrongAnswer(INVALID_A_LENGTH);
// }
// for (int i = 0; i < N - 1; i++) {
// if (a[i] != 0 && a[i] != 1) {
// WrongAnswer(INVALID_A_RANGE);
// }
// }
// if (a != C) {
// WrongAnswer(WRONG_A);
// }
// }
#define pii pair<int, int>
#define ff first
#define ss second
const int MAXN = 1e5 + 5;
int n;
vector<pii> adj[MAXN];
bool vis[MAXN];
int dep[MAXN], idx[MAXN], par[MAXN];
pii edges[MAXN];
vector<int> ans;
vector<int> which;
int d;
void dfs(int u, int p) {
par[u] = p;
for(auto [v, i] : adj[u]) {
if(v == p) continue;
idx[v] = i; dep[v] = dep[u] + 1;
dfs(v, u);
}
}
void magic() {
which.clear();
for(int i = 0; i < n; ++i) vis[i] = true;
for(int i = 0; i < n - 1; ++i) {
if(ans[i] == -1) vis[edges[i].ff] = vis[edges[i].ss] = false;
}
int freq[] = {0, 0, 0};
for(int i = 0; i < n; ++i) {
if(vis[i]) continue;
++freq[dep[i] % 3];
}
int mx = max(freq[0], max(freq[1], freq[2]));
if(freq[0] == mx) d = 0;
else if(freq[1] == mx) d = 1;
else d = 2;
if(mx == 0) return;
// cout << "max missing of depth " << cnt << endl;
vector<int> belt(n - 1, 0), tables(n, 0);
for(int i = 0; i < n; ++i) {
if(dep[i] % 3 == d) tables[i] = 1;
}
// cout << "tables: ";
// for(auto table : tables) cout << table << " "; cout << endl;
for(int i = 0; i < n - 1; ++i) {
if(ans[i] == -1) continue;
if(dep[edges[i].ff] % 3 == d) belt[i] = 1 - ans[i];
else belt[i] = ans[i];
}
which = Query(belt, tables);
}
void Solve(int _n, vector<int> a, vector<int> b) {
n = _n;
ans.resize(n - 1);
for(int i = 0; i < n - 1; ++i) {
edges[i] = {a[i], b[i]};
adj[a[i]].push_back({b[i], i});
adj[b[i]].push_back({a[i], i});
ans[i] = idx[i] = -1;
}
dfs(0, -1);
while(true) {
magic();
if(which.empty()) {
Answer(ans); return;
}
for(int u = 0; u < n; ++u) {
if(dep[u] % 3 != d) continue;
bool up = true;
for(auto [v, i] : adj[u]) {
if(v == par[u]) continue;
if(which[v]) {
// cout << "found" << endl;
up = false;
if(edges[i].ff == u) ans[i] = 0;
else ans[i] = 1;
}
}
if(which[u]) { // all point inwards
// cout << "all inwards" << endl;
up = false;
for(auto [v, i] : adj[u]) {
if(v == par[u]) continue;
if(ans[i] == -1) {
if(edges[i].ff == u) ans[i] = 1;
else ans[i] = 0;
}
}
if(idx[u] != -1) {
if(ans[idx[u]] == -1) {
// cout << "updated up" << endl;
if(edges[idx[u]].ff == u) ans[idx[u]] = 1;
else ans[idx[u]] = 0;
}
}
}
if(up) {
// cout << "went up" << endl;
if(edges[idx[u]].ff == u) ans[idx[u]] = 0;
else ans[idx[u]] = 1;
}
}
// cout << "ans: ";
// for(auto val : ans) cout << val << " ";
// cout << endl;
}
}
// int main() {
// if (scanf("%d", &N) != 1) {
// fprintf(stderr, "Error while reading input.\n");
// exit(1);
// }
// A.resize(N - 1);
// B.resize(N - 1);
// C.resize(N - 1);
// for (int i = 0; i < N - 1; i++) {
// if (scanf("%d", &A[i]) != 1) {
// fprintf(stderr, "Error while reading input.\n");
// exit(1);
// }
// }
// for (int i = 0; i < N - 1; i++) {
// if (scanf("%d", &B[i]) != 1) {
// fprintf(stderr, "Error while reading input.\n");
// exit(1);
// }
// }
// for (int i = 0; i < N - 1; i++) {
// if (scanf("%d", &C[i]) != 1) {
// fprintf(stderr, "Error while reading input.\n");
// exit(1);
// }
// }
// Solve(N, A, B);
// if (!answered) {
// WrongAnswer(NO_ANSWER);
// }
// printf("Accepted: %d\n", query_count);
// return 0;
// }
详细
Subtask #1:
score: 1
Accepted
Test #1:
score: 1
Accepted
time: 2ms
memory: 8036kb
input:
random1 2 0 1 1 0xC321A02965AC2640
output:
Accepted: 1
result:
ok correct
Test #2:
score: 0
Accepted
time: 0ms
memory: 6284kb
input:
random1 2 1 0 0 0x8A99AD9552B2C218
output:
Accepted: 1
result:
ok correct
Test #3:
score: 0
Accepted
time: 1ms
memory: 7912kb
input:
random1 2 1 0 1 0x024D21FA307D148D
output:
Accepted: 1
result:
ok correct
Test #4:
score: 0
Accepted
time: 1ms
memory: 6564kb
input:
random1 2 0 1 0 0x3C96AB23CEB63F75
output:
Accepted: 1
result:
ok correct
Subtask #2:
score: 14
Accepted
Dependency #1:
100%
Accepted
Test #5:
score: 14
Accepted
time: 1ms
memory: 7812kb
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:
Accepted: 4
result:
ok correct
Test #6:
score: 0
Accepted
time: 1ms
memory: 7700kb
input:
random1 30 18 20 12 0 13 2 9 11 24 7 15 26 17 19 23 10 20 16 3 11 24 1 18 19 1 28 22 6 6 26 21 5 27 27 14 15 8 0 17 5 16 3 10 29 13 14 25 28 25 23 8 9 4 2 4 12 7 22 1 0 0 0 1 0 0 1 0 0 0 1 0 1 0 1 1 0 1 1 0 0 0 1 1 1 1 0 1 0x139BEEDAC0AE4AFB
output:
Accepted: 4
result:
ok correct
Test #7:
score: 0
Accepted
time: 1ms
memory: 6948kb
input:
priority 30 15 20 29 0 10 9 28 26 23 6 19 20 8 13 27 27 1 7 16 26 10 4 16 1 18 8 5 14 13 9 22 15 24 29 2 3 19 2 3 17 0 7 14 12 5 6 25 18 25 24 11 4 12 23 11 17 21 28 155983625 867841392 695948077 619352269 127722564 849426565 618649370 326405673 698896139 727112455 131828530 787535071 635627968 4725...
output:
Accepted: 4
result:
ok correct
Test #8:
score: 0
Accepted
time: 1ms
memory: 6844kb
input:
random1 30 11 11 11 11 23 20 11 11 11 26 11 21 11 11 11 27 11 11 11 16 13 17 5 11 11 1 11 14 11 24 28 10 3 11 11 22 25 8 11 29 11 12 15 9 11 19 0 2 11 11 11 11 18 4 11 7 11 6 0 1 1 0 0 1 1 1 0 1 1 0 0 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 1 0xD66348F4E914D783
output:
Accepted: 2
result:
ok correct
Test #9:
score: 0
Accepted
time: 1ms
memory: 6224kb
input:
priority 30 1 7 19 19 21 3 16 25 19 2 4 19 19 22 19 19 27 18 19 24 19 19 19 19 19 19 19 19 28 19 19 29 0 19 19 19 19 15 19 19 10 5 19 6 14 19 19 23 19 8 11 9 26 17 12 13 20 19 175687064 613757478 145110402 817656856 712251185 850089290 510909115 900701092 956086121 136191567 90104148 72809899 345506...
output:
Accepted: 2
result:
ok correct
Test #10:
score: 0
Accepted
time: 1ms
memory: 7240kb
input:
priority 30 22 22 22 16 13 1 13 22 15 6 21 22 2 23 27 22 4 13 3 13 26 5 13 22 9 8 11 25 13 0 14 13 13 29 13 7 18 22 22 13 28 22 13 22 12 22 20 22 24 13 13 10 17 13 22 22 13 19 205508605 212446816 92507839 281454564 232828716 252753556 236784221 262865505 235145960 298570090 277536286 225110287 21565...
output:
Accepted: 2
result:
ok correct
Subtask #3:
score: 10
Accepted
Test #11:
score: 10
Accepted
time: 53ms
memory: 31528kb
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: 46ms
memory: 31508kb
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: 32ms
memory: 32516kb
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: 49ms
memory: 31424kb
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: 75
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Test #15:
score: 75
Accepted
time: 138ms
memory: 26012kb
input:
random1 100000 80421 79656 7373 22779 46143 23525 47891 79913 37297 20998 75128 48153 63344 14542 7176 46311 14404 86722 64420 35721 9418 16518 68787 60231 62713 24600 3621 36142 16253 35726 59248 8570 29713 29710 65003 65386 98313 32539 48464 79006 7464 99396 45447 11929 44648 44081 94041 40159 307...
output:
Accepted: 7
result:
ok correct
Test #16:
score: 0
Accepted
time: 139ms
memory: 25888kb
input:
random1 100000 47543 22001 16105 85619 83739 65453 81631 39199 45451 20382 85595 14410 39199 30963 55201 76378 25120 7516 39199 54202 40278 55022 44298 24421 18026 66509 33880 81569 24498 99677 49879 5902 76830 19128 34499 73731 32890 52171 54572 39199 91782 49370 45817 61462 23515 15408 40298 74640...
output:
Accepted: 7
result:
ok correct
Test #17:
score: 0
Accepted
time: 144ms
memory: 25684kb
input:
random1 100000 54154 40864 51853 60873 46781 94584 40170 53625 38806 77573 2040 39786 34858 81565 80712 35628 88600 17657 29042 78470 12465 42107 99871 96640 83887 26160 67221 77210 16548 76907 36070 44287 83854 17095 84838 80345 84838 81932 77302 34933 63457 76048 85028 48884 95405 88687 84838 3426...
output:
Accepted: 7
result:
ok correct
Test #18:
score: 0
Accepted
time: 134ms
memory: 25640kb
input:
random1 100000 46303 33536 68847 90526 86976 41157 92976 55277 95773 61228 97873 17248 83140 45767 29523 34039 86976 87777 10360 74411 59948 86976 36897 96274 84266 22272 96274 96418 59791 38698 43246 7985 40195 99464 50308 47573 52887 79400 10704 67939 43632 18945 87838 87264 79027 20493 65917 8697...
output:
Accepted: 7
result:
ok correct
Test #19:
score: 0
Accepted
time: 233ms
memory: 25232kb
input:
random1 100000 83611 17213 87562 59306 20020 51610 30839 25762 52114 42830 75713 2390 28217 97024 7915 27090 860 42410 62147 79947 49279 57158 67068 28551 40726 37442 70900 695 38668 92005 24316 63893 61476 18296 31324 2908 81500 37570 90151 93028 17697 90387 89885 75850 10342 18198 33467 89357 3699...
output:
Accepted: 13
result:
ok correct
Test #20:
score: 0
Accepted
time: 226ms
memory: 26048kb
input:
priority 100000 34668 55115 28428 4188 5224 57930 19720 34748 80374 24826 73407 18811 40398 55419 34425 49986 7091 28878 39639 3279 34169 44061 15708 76855 64905 76437 28776 75973 85318 20756 27826 75213 76884 741 73071 76150 96103 99190 10598 36246 59779 85624 75485 48003 32691 32900 44660 9131 370...
output:
Accepted: 12
result:
ok correct
Test #21:
score: 0
Accepted
time: 131ms
memory: 28496kb
input:
priority 100000 8272 58707 53325 33503 38691 8924 23902 10906 10997 96511 35433 36047 75288 5749 82275 55585 59320 19906 16161 51013 24088 3579 52846 80048 79350 77323 45373 11964 60563 32793 15132 89763 7376 26995 66940 69425 47193 17718 76475 67083 2881 42816 87861 80109 80894 30605 93227 36302 46...
output:
Accepted: 6
result:
ok correct
Test #22:
score: 0
Accepted
time: 58ms
memory: 28044kb
input:
priority 100000 10075 75068 42757 34929 5635 88324 14086 51168 29480 62829 22115 12664 34168 98871 97836 72076 42854 54927 58402 74534 5452 3764 46213 32512 91857 92312 43954 73818 41339 73818 24613 14049 55850 89744 44216 25404 35269 76598 81358 38214 56590 82025 73170 9783 48027 88758 14989 9892 5...
output:
Accepted: 3
result:
ok correct
Test #23:
score: 0
Accepted
time: 100ms
memory: 25768kb
input:
random1 100000 39886 43410 20620 76609 96282 4043 56966 38057 73158 96987 12512 52010 33559 37491 1756 50948 92125 55018 10094 61672 32994 14874 78788 68719 67017 45806 9548 79250 53931 15675 37993 93904 27315 85393 57194 51994 38595 38711 73045 70584 64968 72140 47569 4611 60822 45041 83550 74372 6...
output:
Accepted: 4
result:
ok correct
Test #24:
score: 0
Accepted
time: 91ms
memory: 25356kb
input:
priority 100000 77439 97917 89577 30523 22128 31511 44115 73995 32792 19689 3191 29387 85085 44651 16199 36643 76887 48848 46369 81191 97923 75269 61624 22472 86302 21442 44348 57983 69707 49496 73500 59444 62166 91226 26551 60132 17895 55097 87236 21104 92475 46348 22835 77540 3426 90137 10106 3163...
output:
Accepted: 4
result:
ok correct
Test #25:
score: 0
Accepted
time: 116ms
memory: 25396kb
input:
random1 100000 90056 23481 54991 48747 10869 47171 28644 20929 20508 73186 22594 8629 34162 68826 34638 22030 38313 10262 94043 50634 91602 24716 11039 46202 46636 12297 27686 81910 87812 77670 53585 61515 64012 24724 37439 58388 41191 42491 64679 9997 54580 63520 85314 17969 79293 90747 747 63267 7...
output:
Accepted: 5
result:
ok correct
Test #26:
score: 0
Accepted
time: 109ms
memory: 25400kb
input:
priority 100000 82983 53806 58721 49562 46682 2205 64805 49213 32078 11101 90854 73323 28047 3391 73634 20005 38351 30472 2735 67042 33968 81977 18390 34268 52700 77158 59135 76206 51619 71525 36184 24003 7570 57660 15904 42348 38319 72567 70668 61496 23725 8465 99563 69558 17813 58605 66206 90221 3...
output:
Accepted: 5
result:
ok correct
Test #27:
score: 0
Accepted
time: 119ms
memory: 25224kb
input:
priority 100000 23687 72079 84228 5605 43655 23367 86248 30399 85734 13059 96277 31021 28262 94026 784 43550 31733 63840 5044 38346 31111 34745 44054 56928 77101 67424 70437 91204 10371 9335 51851 35025 22270 77070 46995 92655 5539 76526 94191 89673 46321 94461 90070 66428 77614 30022 20664 11834 20...
output:
Accepted: 5
result:
ok correct
Test #28:
score: 0
Accepted
time: 43ms
memory: 25208kb
input:
random1 100000 75293 75293 45013 47419 50486 75293 97976 75293 31253 2388 32384 75293 75293 75293 82899 75293 46145 75293 88247 80203 61006 91769 39236 75293 75293 64380 82730 75293 79899 16818 64062 49362 75293 75293 32066 92355 81071 5065 75293 28857 82373 92604 16331 75293 75293 79642 23246 75293...
output:
Accepted: 2
result:
ok correct
Test #29:
score: 0
Accepted
time: 55ms
memory: 25080kb
input:
priority 100000 79116 79116 14206 79116 79116 80061 79116 62865 56658 75639 41553 56345 79116 33387 79116 52459 79116 79116 13441 79116 19550 52507 79116 79116 87258 9823 79116 79116 31996 66513 79116 12063 79116 49008 79116 90513 79116 79116 79116 79116 79116 79116 79116 79116 79116 7196 27641 3639...
output:
Accepted: 2
result:
ok correct
Test #30:
score: 0
Accepted
time: 53ms
memory: 26220kb
input:
priority 100000 44306 51652 42855 75382 80249 44306 44306 44306 31081 57343 44306 19931 51652 60560 31830 33369 44306 64444 51652 45394 55433 51652 51652 99164 63176 51652 41944 44306 67152 44306 44306 44306 27574 81557 44306 8308 82963 44306 51652 51652 11776 83746 51652 44306 51652 9979 23480 4984...
output:
Accepted: 2
result:
ok correct