QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#478151#8835. Goodmanmartinga#WA 2ms3512kbC++20810b2024-07-14 17:52:142024-07-14 17:52:15

Judging History

你现在查看的是最新测评结果

  • [2024-07-14 17:52:15]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3512kb
  • [2024-07-14 17:52:14]
  • 提交

answer

#include <bits/stdc++.h>
#define lli long long int
using namespace std;

void solveCase()
{
    int n; cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i]; v[i]--;
    }
    vector<bool> visited(n, false);
    vector<int> solution;
    for (int i = 0; i < n; i++)
    {
        if (!visited[i])
        {
            solution.push_back(i);
            int j = v[i];
            while (j != i)
            {
                solution.push_back(j);
                j = v[j];
            }
        }
    }
    cout << solution[0] + 1;
    for (int i = 1; i < n; i++)
    {
        cout << " " << solution[i] + 1;
    }
    cout << "\n";
}

int main()
{
    int n; cin >> n; while (n--)
    {
        solveCase();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
4
1 2 3 4
6
6 5 4 3 2 1

output:

1 2 3 4
1 6 2 5 3 4

result:

ok Correct (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 3512kb

input:

873
6
1 5 2 4 6 3
6
5 1 6 4 3 2
4
1 4 3 2
6
2 1 6 5 4 3
6
4 5 1 3 6 2
6
6 2 1 5 4 3
5
1 5 4 3 2
6
1 2 6 3 5 4
4
2 1 3 4
6
1 6 4 2 3 5
6
6 1 3 5 2 4
6
2 1 4 5 3 6
6
3 4 1 5 2 6
6
4 1 5 2 6 3
6
5 2 1 4 6 3
6
4 1 6 2 3 5
6
5 1 3 4 6 2
6
6 2 5 4 1 3
6
6 2 5 1 4 3
6
5 2 3 6 4 1
6
6 1 2 5 4 3
6
2 3 4 6 1 ...

output:

1 2 5 6 3 3
1 5 3 6 2 2
1 2 4 3
1 2 2 1 3 6
1 4 3 2 5 6
1 6 3 2 3 1
1 2 5 3 4
1 2 3 6 4 4
1 2 2 1
1 2 6 5 3 4
1 6 4 5 2 2
1 2 2 1 3 4
1 3 2 4 5 3
1 4 2 2 1 4
1 5 6 3 2 3
1 4 2 2 1 4
1 5 6 2 2 1
1 6 3 5 2 3
1 6 3 5 4 2
1 5 4 6 2 3
1 6 3 2 2 1
1 2 3 4 6 5
1 5 2 6 3 3
1 4 2 3 6 5
1 4 2 3 5 2
1 3 2 3 1 ...

result:

wrong answer Participant didn't find permutation (test case 1)