이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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[k][i] = small[i][k] = 1;
goto END;
}
}
for(int k = i+1; k < n; ++k)
big[k][i] = small[i][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";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |