UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#212261#3813. T3Matthew2015ms1208kbC++809b2024-10-13 16:25:032024-10-13 19:37:28

answer

#include <bits/stdc++.h>
using namespace std;
int n, a[100005], ans[100005];
bool cmp()
{
    for (int i = 1; i <= n; i++)
    {
        if (a[i] < ans[i])
            return 1;
        if (a[i] > ans[i])
            return 0;
    }
    return 0;
}
void copy()
{
    for (int i = 1; i <= n; i++)
        ans[i] = a[i];
}
void dfs(int t)
{
    if (t >= n)
    {
        if (cmp())
            copy();
        return;
    }
    swap(a[t + 1], a[(t + 1) / 2]);
    dfs(t + 1);
    swap(a[t + 1], a[(t + 1) / 2]);
    dfs(t + 1);
}
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        {
            cin >> a[i];
            ans[i] = a[i];
        }
    dfs(1);
    for (int i = 1; i <= n; i++)
    {
        cout << ans[i] << " ";
    }
    return 0;
}

详细

小提示:点击横条可展开更详细的信息

Subtask #1:

score: 20
Accepted

Test #1:

score: 20
Accepted
time: 3ms
memory: 1208kb

input:

20
7 8 4 12 6 19 1 5 16 14 15 20 17 18 9 10 13 11 2 3

output:

4 6 1 5 7 8 9 10 2 3 15 20 17 18 19 12 13 11 16 14 

result:

ok 20 numbers

Test #2:

score: 0
Accepted
time: 3ms
memory: 1204kb

input:

20
3 19 17 5 8 14 12 6 15 7 9 4 10 1 20 16 18 13 11 2

output:

3 5 12 6 7 4 1 16 11 2 9 14 10 17 20 19 18 13 15 8 

result:

ok 20 numbers

Test #3:

score: 0
Accepted
time: 3ms
memory: 1204kb

input:

20
13 8 2 19 7 15 5 12 9 17 3 16 4 18 10 1 11 6 14 20

output:

2 7 5 8 3 4 10 1 6 17 19 13 16 15 18 12 11 9 14 20 

result:

ok 20 numbers

Test #4:

score: 0
Accepted
time: 3ms
memory: 1208kb

input:

20
20 19 8 17 11 10 14 7 12 16 15 9 18 13 6 5 4 3 2 1

output:

8 11 10 7 15 9 6 4 2 1 16 19 18 13 14 5 17 3 12 20 

result:

ok 20 numbers

Test #5:

score: 0
Accepted
time: 3ms
memory: 1208kb

input:

20
7 19 18 3 16 15 14 13 20 11 10 9 8 12 6 5 4 2 17 1

output:

7 3 14 13 10 8 6 4 2 1 11 9 15 12 18 5 19 20 17 16 

result:

ok 20 numbers

Subtask #2:

score: 0
Time Limit Exceeded

Test #6:

score: 0
Time Limit Exceeded

input:

40
19 15 20 27 16 11 34 5 21 6 30 3 40 39 12 2 7 13 1 23 37 32 18 28 25 17 33 31 29 36 4 22 10 35 8 ...

output:


result:


Subtask #3:

score: 0
Time Limit Exceeded

Test #11:

score: 0
Time Limit Exceeded

input:

1000
162 57 979 220 75 121 744 693 173 262 399 558 295 360 530 363 977 552 398 101 137 946 85 712 71...

output:


result:


Subtask #4:

score: 0
Time Limit Exceeded

Test #16:

score: 0
Time Limit Exceeded

input:

50000
6014 4637 42967 25211 33048 39571 24304 15155 17748 38901 41356 27235 3880 27971 22842 37080 4...

output:


result:


Subtask #5:

score: 0
Runtime Error

Test #21:

score: 0
Runtime Error

input:

200000
113806 52130 91627 30299 76623 124589 163145 143300 2089 189894 32321 116979 54734 199544 128...

output:


result: