#include <bits/stdc++.h>
using namespace std;
const int N = 102;
int n;
int a[N];
int b[N][N];
int minu[N], maxu[N];
bool stg(int a[], int i)
{
for (int j = 1; j <= n; ++j)
{
if (b[i][j])
{
if (b[i][j] == -1 && a[i] > a[j])
return false;
if (b[i][j] == 1 && a[i] < a[j])
return false;
}
}
return true;
}
int main()
{
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i];
for (int i = 1; i <= n; ++i)
{
for (int j = i + 1; j <= n; ++j)
{
swap(a[i], a[j]);
cout << "query";
for (int k = 1; k <= n; ++k)
cout << ' ' << a[k];
cout << endl;
swap(a[i], a[j]);
int x;
cin >> x;
if (x == 0)
{
if (a[i] < a[j])
{
b[i][j] = -1;
b[j][i] = 1;
}
if (a[i] > a[j])
{
b[i][j] = 1;
b[j][i] = -1;
}
}
}
}
for (int i = 1; i <= n; ++i)
minu[i] = maxu[i] = a[i];
sort(a + 1, a + n + 1);
do
{
bool z = true;
for (int i = 1; i <= n; ++i)
{
if (!stg(a, i))
{
z = false;
break;
}
}
if (z)
{
for (int i = 1; i <= n; ++i)
{
if (a[i] == minu[i])
continue;
if (a[i] < minu[i])
{
for (int j = 1; j <= n; ++j)
minu[j] = a[j];
}
break;
}
for (int i = 1; i <= n; ++i)
{
if (a[i] == maxu[i])
continue;
if (a[i] > maxu[i])
{
for (int j = 1; j <= n; ++j)
maxu[j] = a[j];
}
break;
}
}
} while (next_permutation(a + 1, a + n + 1));
cout << "end" << endl;
for (int i = 1; i <= n; ++i)
cout << minu[i] << ' ';
cout << endl;
for (int i = 1; i <= n; ++i)
cout << maxu[i] << ' ';
cout << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
400 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3060 ms |
376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3012 ms |
316 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3022 ms |
248 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |