QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#820871#9891. TravelerN_z_AC ✓33ms3772kbC++23630b2024-12-19 08:52:012024-12-19 08:52:10

Judging History

This is the latest submission verdict.

  • [2024-12-19 08:52:10]
  • Judged
  • Verdict: AC
  • Time: 33ms
  • Memory: 3772kb
  • [2024-12-19 08:52:01]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        vector<int>vis(n+1);
        vis[0]=vis[1]=1;cout<<1;
        auto run=[&](int pos){if(!vis[pos])cout<<' '<<pos,vis[pos]=1;};
        int x=1;
        while(x<=n)
        {
            run(x);
            if(n/2==x)
            {
                if(n&1^1)run(n),n--;
                for(int x=n;!vis[x];x-=2)
                run(x),run(x/2),run(x-1);
                break;
            }
            if(!vis[x-1])x--;else x*=2;
        }
        cout<<'\n';
    }
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3568kb

input:

2
2
9

output:

1 2
1 2 4 9 8 7 3 6 5

result:

ok ok 2 cases.

Test #2:

score: 0
Accepted
time: 33ms
memory: 3772kb

input:

999
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
...

output:

1
1 2
1 3 2
1 2 4 3
1 2 5 4 3
1 2 4 3 6 5
1 2 4 3 7 6 5
1 2 4 8 7 3 6 5
1 2 4 9 8 7 3 6 5
1 2 4 3 6 5 10 9 8 7
1 2 4 3 6 5 11 10 9 8 7
1 2 4 3 6 12 11 5 10 9 8 7
1 2 4 3 6 13 12 11 5 10 9 8 7
1 2 4 3 6 5 10 9 8 7 14 13 12 11
1 2 4 3 6 5 10 9 8 7 15 14 13 12 11
1 2 4 3 6 5 10 9 8 16 15 7 14 13 12 11
...

result:

ok ok 999 cases.

Extra Test:

score: 0
Extra Test Passed