QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#818305 | #8812. Library 3 | makrav# | 21 | 123ms | 4140kb | C++20 | 2.9kb | 2024-12-17 18:29:01 | 2024-12-17 18:29:01 |
Judging History
answer
#include "library3.h"
#include <bits/stdc++.h>
#include <cassert>
#include <vector>
using namespace std;
#define pb push_back
#define sz(x) (int)(x).size()
mt19937 rnd(time(NULL));
template<typename T>
void shuf(vector<T>&x) {
for (int i = 1; i < x.size(); i++) {
swap(x[i], x[rnd() % i]);
}
}
void solve(int N) {
int n = N;
vector<int> Q(n);
for (int i = 0; i < n; i++) Q[i] = i;
int la, req = 0;
while (true) {
shuf(Q);
la = query(Q);
req++;
if (la == 0) {
answer(Q); return;
}
if (la >= n - 2) break;
}
//cout << req << endl;
vector<vector<int>> loops = {{0}};
if (la == n - 1) {
for (int i = 1; i < n; i++) loops.back().pb(i);
} else {
loops.pb({});
for (int i = 1; i < n; i++) {
swap(Q[0], Q[i]);
int na = query(Q);
if (na == 0) {
answer(Q);
return;
}
swap(Q[0], Q[i]);
if (na < la) {
loops[0].pb(i);
} else loops[1].pb(i);
}
}
// for (int u : Q) cout << u << ' ';
// cout << endl;
while (true) {
// cout << "iter\n";
// for (auto u : loops) {
// for (int v : u) cout << v << ' ';
// cout << endl;
// }
int sw = 0;
bool need = false;
for (auto l : loops) {
if (l.size() >= 2) {
need = true;
int ind1 = rnd() % sz(l);
int ind2 = (ind1 + 1 + rnd() % (sz(l) - 1)) % sz(l);
swap(Q[l[ind1]], Q[l[ind2]]);
sw++;
}
}
if (!need) break;
int curans = la - sw;
//cout << "check " << curans << ' ' <<query(Q) << endl;
vector<vector<int>> newloops;
for (int i = 0; i < sz(loops); i++) {
if (loops[i].size() == 1) {
newloops.pb(loops[i]);
continue;
}
for (int j = 0; j < 2; j++) newloops.pb({});
newloops.back().pb(loops[i][0]);
for (int j = 1; j < loops[i].size(); j++) {
if (loops[i].size() == 2) {
newloops[sz(newloops) - 2].pb(loops[i][j]);
continue;
}
swap(Q[loops[i][j]], Q[loops[i][0]]);
int rs = query(Q);
if (rs == 0) {
answer(Q);
return;
}
if (rs < curans) {
newloops.back().pb(loops[i][j]);
} else {
newloops[sz(newloops) - 2].pb(loops[i][j]);
}
swap(Q[loops[i][j]], Q[loops[i][0]]);
}
}
swap(loops, newloops);
la = curans;
}
answer(Q);
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 2
Accepted
Test #1:
score: 2
Accepted
time: 0ms
memory: 3824kb
input:
2 1
output:
? 1 0 ! 0 1 -
result:
ok Accepted
Test #2:
score: 2
Accepted
time: 0ms
memory: 4100kb
input:
3 2 2 2
output:
? 2 0 1 ? 0 1 2 ? 2 0 1 ! 1 2 0 -
result:
ok Accepted
Test #3:
score: 2
Accepted
time: 1ms
memory: 3808kb
input:
4 2 1 3 1 2 0
output:
? 2 0 3 1 ? 0 2 3 1 ? 3 0 2 1 ? 1 0 3 2 ? 2 0 3 1 ? 1 2 3 0 ! 1 2 3 0 -
result:
ok Accepted
Test #4:
score: 2
Accepted
time: 1ms
memory: 3804kb
input:
5 2 4 4 4 4 2 2 0
output:
? 2 0 4 1 3 ? 4 3 1 0 2 ? 2 4 1 0 3 ? 1 2 4 0 3 ? 0 2 1 4 3 ? 3 2 1 0 4 ? 3 2 1 0 4 ? 3 0 2 1 4 ! 3 0 2 1 4 -
result:
ok Accepted
Test #5:
score: 2
Accepted
time: 1ms
memory: 3796kb
input:
5 3 4 2 4 2 2 2
output:
? 2 0 4 1 3 ? 0 2 4 1 3 ? 4 0 2 1 3 ? 1 0 4 2 3 ? 3 0 4 1 2 ? 4 1 3 0 2 ? 2 1 4 0 3 ! 3 1 2 0 4 -
result:
ok Accepted
Test #6:
score: 2
Accepted
time: 0ms
memory: 3884kb
input:
6 5 5 3 3 3 3 2 2 2 4 1 1 3 2 2
output:
? 2 0 4 5 3 1 ? 4 2 0 5 3 1 ? 0 4 2 5 3 1 ? 5 4 0 2 3 1 ? 3 4 0 5 2 1 ? 1 4 0 5 3 2 ? 0 4 2 5 1 3 ? 5 4 0 2 1 3 ? 1 4 0 5 2 3 ? 3 4 0 5 1 2 ? 1 4 2 5 0 3 ? 5 4 1 2 0 3 ? 0 4 1 5 2 3 ? 2 4 1 5 0 3 ? 5 4 2 1 0 3 ! 1 4 5 2 0 3 -
result:
ok Accepted
Test #7:
score: 2
Accepted
time: 1ms
memory: 3804kb
input:
6 4 5 5 3 3 3 3 1 3
output:
? 2 0 4 5 3 1 ? 0 2 4 5 3 1 ? 4 0 2 5 3 1 ? 5 0 4 2 3 1 ? 3 0 4 5 2 1 ? 1 0 4 5 3 2 ? 5 4 0 1 3 2 ? 3 4 0 5 1 2 ? 2 4 0 5 3 1 ! 3 4 0 2 1 5 -
result:
ok Accepted
Test #8:
score: 2
Accepted
time: 1ms
memory: 3800kb
input:
6 4 5 3 3 3 5 1 1 3 2 0
output:
? 2 0 4 5 3 1 ? 0 2 4 5 3 1 ? 4 0 2 5 3 1 ? 5 0 4 2 3 1 ? 3 0 4 5 2 1 ? 1 0 4 5 3 2 ? 4 1 3 5 2 0 ? 5 1 4 3 2 0 ? 2 1 4 5 3 0 ? 5 1 3 4 2 0 ? 4 1 5 3 2 0 ! 4 1 5 3 2 0 -
result:
ok Accepted
Test #9:
score: 2
Accepted
time: 1ms
memory: 3792kb
input:
5 2 2 2 2 4 2 2 4 4 2 0
output:
? 2 0 4 1 3 ? 4 3 1 0 2 ? 3 0 4 2 1 ? 4 3 1 0 2 ? 0 2 4 3 1 ? 3 0 4 2 1 ? 4 3 0 2 1 ? 2 3 4 0 1 ? 1 3 4 2 0 ? 0 3 4 1 2 ? 4 0 3 1 2 ! 4 0 3 1 2 -
result:
ok Accepted
Test #10:
score: 2
Accepted
time: 0ms
memory: 3900kb
input:
6 4 3 3 5 3 3 4 4 4 2 2 2
output:
? 2 0 4 5 3 1 ? 0 2 4 5 3 1 ? 4 0 2 5 3 1 ? 5 0 4 2 3 1 ? 3 0 4 5 2 1 ? 1 0 4 5 3 2 ? 0 4 2 5 3 1 ? 2 0 4 5 3 1 ? 3 0 2 5 4 1 ? 1 0 2 5 3 4 ? 1 2 3 5 0 4 ? 1 0 2 5 3 4 ! 1 3 0 5 2 4 -
result:
ok Accepted
Subtask #2:
score: 19
Accepted
Dependency #1:
100%
Accepted
Test #11:
score: 19
Accepted
time: 0ms
memory: 4104kb
input:
7 3 5 4 4 6 6 4 4 2 2 4 2 3 3 1
output:
? 2 0 6 5 3 1 4 ? 0 4 5 1 6 2 3 ? 4 0 5 1 6 2 3 ? 5 4 0 1 6 2 3 ? 1 4 5 0 6 2 3 ? 6 4 5 1 0 2 3 ? 2 4 5 1 6 0 3 ? 3 4 5 1 6 2 0 ? 4 0 5 6 1 3 2 ? 5 4 0 6 1 3 2 ? 3 4 5 6 1 0 2 ? 2 4 5 6 1 3 0 ? 4 5 0 6 1 3 2 ? 0 4 5 6 1 3 2 ? 2 4 0 6 1 3 5 ! 2 0 4 6 1 3 5 -
result:
ok Accepted
Test #12:
score: 19
Accepted
time: 2ms
memory: 3812kb
input:
50 44 47 44 47 46 45 48 47 47 47 47 49 47 47 47 47 49 47 47 47 47 47 47 47 47 47 47 49 47 49 47 47 47 47 49 47 49 47 47 49 47 47 47 47 47 47 47 47 49 49 47 47 49 47 47 47 47 47 45 45 47 45 45 45 45 47 47 47 45 45 47 47 47 47 45 45 45 47 45 45 45 45 47 45 45 47 47 47 47 47 45 47 45 47 45 45 47 45 47 ...
output:
? 34 7 48 21 42 39 32 29 9 26 0 28 36 20 24 2 4 1 31 49 17 5 15 41 10 33 13 23 43 47 6 12 25 16 11 22 45 14 44 8 46 19 40 35 30 37 3 27 38 18 ? 14 31 19 1 34 38 39 16 18 24 49 27 32 41 30 33 23 9 25 21 37 26 35 47 20 45 17 46 36 3 2 5 11 22 42 48 29 6 7 28 13 43 12 0 44 15 4 40 10 8 ? 12 23 7 8 39 1...
result:
ok Accepted
Test #13:
score: 19
Accepted
time: 7ms
memory: 4112kb
input:
98 92 91 94 89 92 95 96 95 95 95 95 97 95 95 95 95 95 95 95 97 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 97 95 95 95 97 95 97 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 97 95 95 95 97 95 97 95 95 95 95 95 95 95 95 95 95 95 97 95 95 95 95 95 95 95 95 95 97 95 95 95 97 95 95 95 95 95 95 95 95 ...
output:
? 34 7 68 59 42 84 32 29 80 26 0 85 71 66 24 2 77 74 82 49 17 5 15 79 10 33 13 23 56 92 88 94 25 16 69 75 67 63 81 83 97 19 72 55 30 54 52 27 93 78 38 3 58 28 96 35 62 53 51 21 48 40 87 64 14 76 20 91 60 11 86 65 89 44 1 22 36 4 18 41 9 73 31 70 39 57 8 43 6 90 61 95 47 50 12 45 37 46 ? 86 34 64 63 ...
result:
ok Accepted
Test #14:
score: 19
Accepted
time: 7ms
memory: 4120kb
input:
98 94 93 96 97 97 97 95 95 95 97 95 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 95 97 97 97 97 97 97 97 97 97 95 97 97 97 97 97 97 97 97 97 97 97 95 97 97 97 97 97 97 97 97 97 97 97 97 95 97 97 97 97 97 97 97 97 97 97 97 97 97 97 95 97 97 97 97 95 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 ...
output:
? 34 7 68 59 42 84 32 29 80 26 0 85 71 66 24 2 77 74 82 49 17 5 15 79 10 33 13 23 56 92 88 94 25 16 69 75 67 63 81 83 97 19 72 55 30 54 52 27 93 78 38 3 58 28 96 35 62 53 51 21 48 40 87 64 14 76 20 91 60 11 86 65 89 44 1 22 36 4 18 41 9 73 31 70 39 57 8 43 6 90 61 95 47 50 12 45 37 46 ? 86 34 64 63 ...
result:
ok Accepted
Test #15:
score: 19
Accepted
time: 7ms
memory: 3816kb
input:
99 90 94 92 94 96 92 94 94 94 94 96 94 96 98 98 98 98 98 98 96 98 98 98 98 96 98 98 98 98 98 96 96 98 96 96 98 98 98 98 98 98 96 98 98 98 98 96 98 96 98 98 96 98 96 98 96 98 96 96 98 98 98 98 96 96 98 96 98 98 98 96 96 96 96 96 98 96 98 98 98 98 98 96 98 96 98 96 96 98 98 96 98 98 96 98 98 98 96 96 ...
output:
? 34 7 68 59 42 84 32 29 80 26 0 85 71 66 24 2 77 74 82 49 17 5 15 79 10 33 13 23 56 92 88 94 25 16 69 75 67 63 81 83 97 19 72 55 30 54 52 27 93 78 38 3 58 28 96 35 62 98 51 21 48 40 87 64 14 76 20 91 60 11 86 65 89 44 1 22 36 4 18 41 9 73 31 70 39 57 8 43 6 90 61 95 47 50 12 45 37 46 53 ? 72 22 81 ...
result:
ok Accepted
Test #16:
score: 19
Accepted
time: 2ms
memory: 3892kb
input:
99 96 92 96 92 94 94 92 96 94 94 94 92 94 90 94 92 96 96 96 90 92 92 94 92 96 92 92 96 92 96 94 94 96 94 94 90 94 94 92 94 92 94 94 96 92 92 94 92 96 96 90 92 96 94 90 94 98 96 96 96 96 96 96 96 96 96 98 96 96 96 96 96 98 96 96 96 96 96 96 96 96 98 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 ...
output:
? 34 7 68 59 42 84 32 29 80 26 0 85 71 66 24 2 77 74 82 49 17 5 15 79 10 33 13 23 56 92 88 94 25 16 69 75 67 63 81 83 97 19 72 55 30 54 52 27 93 78 38 3 58 28 96 35 62 98 51 21 48 40 87 64 14 76 20 91 60 11 86 65 89 44 1 22 36 4 18 41 9 73 31 70 39 57 8 43 6 90 61 95 47 50 12 45 37 46 53 ? 72 22 81 ...
result:
ok Accepted
Test #17:
score: 19
Accepted
time: 6ms
memory: 3816kb
input:
99 96 92 96 94 94 94 94 94 94 92 92 96 92 94 92 92 96 92 94 92 94 92 96 94 94 92 94 94 96 94 94 94 96 90 96 94 96 94 96 96 94 96 94 92 90 94 94 96 92 94 96 92 92 92 96 94 92 96 94 92 96 92 94 96 94 92 94 92 94 96 90 96 96 94 92 94 94 96 92 92 94 92 96 94 96 92 96 90 96 94 96 94 96 96 96 94 94 94 92 ...
output:
? 34 7 68 59 42 84 32 29 80 26 0 85 71 66 24 2 77 74 82 49 17 5 15 79 10 33 13 23 56 92 88 94 25 16 69 75 67 63 81 83 97 19 72 55 30 54 52 27 93 78 38 3 58 28 96 35 62 98 51 21 48 40 87 64 14 76 20 91 60 11 86 65 89 44 1 22 36 4 18 41 9 73 31 70 39 57 8 43 6 90 61 95 47 50 12 45 37 46 53 ? 72 22 81 ...
result:
ok Accepted
Test #18:
score: 19
Accepted
time: 3ms
memory: 3792kb
input:
100 95 98 97 97 97 97 97 97 97 99 97 99 97 99 97 97 97 97 97 99 99 99 97 97 99 97 99 97 97 99 99 97 99 99 99 97 99 97 97 97 97 97 97 99 99 97 97 99 97 99 97 97 99 97 99 97 97 97 99 99 97 99 97 97 97 99 97 97 97 99 99 99 97 99 97 97 97 99 97 99 97 97 97 99 97 99 97 97 97 97 97 97 97 97 97 99 99 97 97...
output:
? 34 7 68 59 42 84 32 29 80 26 0 85 71 66 24 2 77 74 82 49 17 5 15 79 10 33 13 23 56 92 88 94 25 16 69 75 67 63 81 83 97 99 72 55 30 54 52 27 93 78 38 3 58 28 96 35 62 98 51 21 48 40 87 64 14 76 20 91 60 11 86 65 89 44 1 22 36 4 18 41 9 73 31 70 39 57 8 43 6 90 61 95 47 50 12 45 37 46 53 19 ? 59 93 ...
result:
ok Accepted
Test #19:
score: 19
Accepted
time: 7ms
memory: 3848kb
input:
100 93 88 95 98 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 99 97 97 97 97...
output:
? 34 7 68 59 42 84 32 29 80 26 0 85 71 66 24 2 77 74 82 49 17 5 15 79 10 33 13 23 56 92 88 94 25 16 69 75 67 63 81 83 97 99 72 55 30 54 52 27 93 78 38 3 58 28 96 35 62 98 51 21 48 40 87 64 14 76 20 91 60 11 86 65 89 44 1 22 36 4 18 41 9 73 31 70 39 57 8 43 6 90 61 95 47 50 12 45 37 46 53 19 ? 59 93 ...
result:
ok Accepted
Test #20:
score: 19
Accepted
time: 8ms
memory: 4116kb
input:
100 90 93 94 93 96 95 92 95 96 93 96 93 96 91 94 93 98 97 97 97 97 97 97 97 97 97 97 99 97 97 97 97 97 97 97 97 97 99 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97...
output:
? 34 7 68 59 42 84 32 29 80 26 0 85 71 66 24 2 77 74 82 49 17 5 15 79 10 33 13 23 56 92 88 94 25 16 69 75 67 63 81 83 97 99 72 55 30 54 52 27 93 78 38 3 58 28 96 35 62 98 51 21 48 40 87 64 14 76 20 91 60 11 86 65 89 44 1 22 36 4 18 41 9 73 31 70 39 57 8 43 6 90 61 95 47 50 12 45 37 46 53 19 ? 59 93 ...
result:
ok Accepted
Test #21:
score: 19
Accepted
time: 3ms
memory: 3920kb
input:
100 94 93 98 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 99 99 97 99 97 99 97 97 97 97 99 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 99 97 97 97 97 97 97 97 99 97 97 97 97 97 97 97 97 97 97 99 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97...
output:
? 34 7 68 59 42 84 32 29 80 26 0 85 71 66 24 2 77 74 82 49 17 5 15 79 10 33 13 23 56 92 88 94 25 16 69 75 67 63 81 83 97 99 72 55 30 54 52 27 93 78 38 3 58 28 96 35 62 98 51 21 48 40 87 64 14 76 20 91 60 11 86 65 89 44 1 22 36 4 18 41 9 73 31 70 39 57 8 43 6 90 61 95 47 50 12 45 37 46 53 19 ? 59 93 ...
result:
ok Accepted
Test #22:
score: 19
Accepted
time: 9ms
memory: 4140kb
input:
99 94 92 94 96 96 94 96 94 92 94 92 94 94 96 94 96 92 92 94 94 94 92 94 94 96 94 96 90 94 94 94 94 96 96 94 96 94 92 92 94 94 90 94 94 92 96 94 96 90 92 90 96 90 96 92 96 92 92 96 92 96 94 92 90 94 96 94 96 92 96 94 90 90 94 94 94 94 96 90 92 96 94 94 96 90 96 92 94 96 94 94 94 92 96 98 98 98 96 96 ...
output:
? 34 7 68 59 42 84 32 29 80 26 0 85 71 66 24 2 77 74 82 49 17 5 15 79 10 33 13 23 56 92 88 94 25 16 69 75 67 63 81 83 97 19 72 55 30 54 52 27 93 78 38 3 58 28 96 35 62 98 51 21 48 40 87 64 14 76 20 91 60 11 86 65 89 44 1 22 36 4 18 41 9 73 31 70 39 57 8 43 6 90 61 95 47 50 12 45 37 46 53 ? 72 22 81 ...
result:
ok Accepted
Test #23:
score: 19
Accepted
time: 9ms
memory: 4116kb
input:
100 98 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 99 97 97 97 97 97 97 97 97 97...
output:
? 63 78 47 21 75 67 4 23 41 62 76 70 98 71 15 28 13 60 51 77 39 68 31 55 84 54 43 97 94 2 11 7 65 3 66 14 40 61 24 33 29 46 73 52 10 19 91 83 64 96 80 56 42 17 20 35 0 30 69 44 50 74 79 26 81 8 25 95 82 72 89 49 16 34 58 99 85 93 90 5 32 9 53 87 57 38 92 27 48 6 37 36 1 22 12 86 59 45 88 18 ? 78 63 ...
result:
ok Accepted
Test #24:
score: 19
Accepted
time: 6ms
memory: 3824kb
input:
100 92 93 96 93 94 91 98 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 99 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 99 97 97 97 97 97 97...
output:
? 63 78 47 21 75 67 4 23 41 62 76 70 98 71 15 28 13 60 51 77 39 68 31 55 84 54 43 97 94 2 11 7 65 3 66 14 40 61 24 33 29 46 73 52 10 19 91 83 64 96 80 56 42 17 20 35 0 30 69 44 50 74 79 26 81 8 25 95 82 72 89 49 16 34 58 99 85 93 90 5 32 9 53 87 57 38 92 27 48 6 37 36 1 22 12 86 59 45 88 18 ? 66 2 4...
result:
ok Accepted
Subtask #3:
score: 0
Wrong Answer
Dependency #2:
100%
Accepted
Test #25:
score: 0
Wrong Answer
time: 123ms
memory: 3884kb
input:
498 490 487 488 491 494 487 490 493 490 491 490 493 486 493 492 491 494 489 488 493 492 491 490 489 494 491 490 491 492 491 492 493 490 491 490 489 492 491 492 493 492 493 492 493 492 491 494 489 494 491 490 491 490 491 492 489 490 493 490 489 494 491 490 491 492 495 492 491 492 493 494 489 494 493 ...
output:
? 449 78 138 152 358 338 154 342 176 110 288 100 167 71 425 320 402 363 247 252 237 164 227 349 127 266 43 132 220 356 144 7 270 3 184 483 428 339 24 346 443 199 258 52 102 169 261 140 160 96 444 414 42 204 375 405 0 461 230 44 130 374 283 225 268 409 477 95 162 442 280 126 274 191 133 332 387 479 2...
result:
wrong answer Wrong Answer [4]