#include <bits/stdc++.h>
using namespace std;
const int MAXN = 107;
int n;
int niz[MAXN];
vector<int> ind, v, rod[MAXN], djeca[MAXN];
vector<pair<int, int> > pravila;
int preb[MAXN], bio[MAXN], ispis[MAXN];
bool cmp (int a, int b) {
return niz[a] < niz[b];
}
bool dobro (int x) {
bio[x] = 1;
if (preb[x]) return false;
for (auto nx: rod[x]) {
if (!bio[nx]) {
if (!dobro (nx)) return false;
}
}
return true;
}
bool pitaj (int x, int y) {
int novi_niz[MAXN];
for (int i = 0; i < n; i++) novi_niz[i] = niz[i];
for (int i = 0; i < n; i++) preb[i] = 0;
for (int i = 0; i < n; i++) bio[i] = 0;
preb[ind[x]] = 1;
for (int i = x + 1; i < y; i++) {
if (!dobro (ind[i])) preb[ind[i]] = 1;
}
if (!dobro (ind[y])) return true;
v.clear ();
for (int i = x; i <= y; i++) {
if (!preb[ind[i]]) v.push_back (i);
}
for (int i = x; i <= y; i++) {
if (preb[ind[i]]) v.push_back (i);
}
for (int i = x; i <= y; i++) novi_niz[ind[v[i - x]]] = i + 1;
cout << "query ";
for (int i = 0; i < n; i++) cout << novi_niz[i] << ' ';
cout << endl;
int a;
cin >> a;
if (a) return true;
else return false;
}
void gore (int x) {
bio[x] = 1;
for (auto nx: rod[x]) {
if (!bio[nx]) gore (nx);
}
v.push_back (x);
}
void dole (int x) {
bio[x] = 1;
for (auto nx: djeca[x]) {
if (!bio[nx]) dole (nx);
}
v.push_back (x);
}
int main () {
cin >> n;
for (int i = 0; i < n; i++) cin >> niz[i];
for (int i = 0; i < n; i++) ind.push_back (i);
sort (ind.begin (), ind.end (), cmp);
for (int i = 1; i < n; i++) {
for (int j = i - 1; j >= 0; j--) {
if (!pitaj (j, i)) {
pravila.push_back ({ind[j], ind[i]});
rod[ind[i]].push_back (ind[j]);
djeca[ind[j]].push_back (ind[i]);
}
}
}
cout << "end" << endl;
for (int i = 0; i < n; i++) sort (rod[i].begin (), rod[i].end ());
v.clear ();
memset (bio, 0, sizeof (bio));
for (int i = 0; i < n; i++) {
if (!bio[i]) gore (i);
}
for (int i = 0; i < n; i++) ispis[v[i]] = i + 1;
for (int i = 0; i < n; i++) cout << ispis[i] << ' ';
cout << endl;
for (int i = 0; i < n; i++) sort (djeca[i].begin (), djeca[i].end ());
v.clear ();
memset (bio, 0, sizeof (bio));
for (int i = 0; i < n; i++) {
if (!bio[i]) dole (i);
}
for (int i = 0; i < n; i++) ispis[v[i]] = n - i;
for (int i = 0; i < n; i++) cout << ispis[i] << ' ';
cout << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
596 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
14 ms |
344 KB |
Output is correct |
3 |
Correct |
17 ms |
344 KB |
Output is correct |
4 |
Correct |
18 ms |
344 KB |
Output is correct |
5 |
Correct |
5 ms |
344 KB |
Output is correct |
6 |
Correct |
22 ms |
596 KB |
Output is correct |
7 |
Correct |
3 ms |
344 KB |
Output is correct |
8 |
Correct |
4 ms |
344 KB |
Output is correct |
9 |
Correct |
17 ms |
344 KB |
Output is correct |
10 |
Correct |
7 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
704 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
344 KB |
Output is correct |
2 |
Correct |
45 ms |
344 KB |
Output is correct |
3 |
Correct |
37 ms |
416 KB |
Output is correct |
4 |
Correct |
46 ms |
1232 KB |
Output is correct |
5 |
Correct |
66 ms |
1208 KB |
Output is correct |
6 |
Correct |
69 ms |
1216 KB |
Output is correct |
7 |
Correct |
46 ms |
992 KB |
Output is correct |
8 |
Correct |
49 ms |
1224 KB |
Output is correct |
9 |
Correct |
53 ms |
960 KB |
Output is correct |
10 |
Incorrect |
50 ms |
936 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |