#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
int n;
int a[109];
int big[109][109];
int small[109][109];
int q(int idx, int put){
cout << "query ";
for(int i = 0; i <= put; ++i){
if(i == idx) continue;
cout << a[i] << " ";
}
cout << a[idx] << " ";
for(int i = put+1; i < n; ++i){
if(i == idx) continue;
cout << a[i] << " ";
}
cout << endl;
int t1;
cin >> t1;
return t1;
}
void sf(int l, int r){
if(l >= r)
return;
int look = a[l];
int lid = l;
for(int i = l+1; i <= r; ++i){
if(big[look][a[i]] == 1){
swap(a[lid], a[i]);
swap(a[i], a[lid+1]);
++lid;
}
}
sf(l, lid-1);
sf(lid+1, r);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
cin >> n;
for(int i = 0; i < n; ++i)
cin >> a[i];
for(int i = 0; i < n-1; ++i){
for(int j = n-1; j > i; --j){
if(q(i, j) == 1){
for(int k = j+1; k < n; ++k)
big[a[k]][a[i]] = small[a[i]][a[k]] = 1;
goto END;
}
}
for(int k = i+1; k < n; ++k)
big[a[k]][a[i]] = small[a[i]][a[k]] = 1;
END:;
}
cout << "end\n";
sort(a, a+n);
sf(0, n-1);
for(int i = 0; i < n; ++i)
cout << a[i] << " ";
cout << "\n";
sort(a, a+n, greater<int>());
sf(0, n-1);
for(int i = 0; i < n; ++i)
cout << a[i] << " ";
cout << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
416 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
39 ms |
408 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |