QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#460611#8835. GoodmanQwertyPi#WA 0ms5660kbC++14849b2024-07-01 21:37:282024-07-01 21:37:28

Judging History

This is the latest submission verdict.

  • [2024-07-01 21:37:28]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 5660kb
  • [2024-07-01 21:37:28]
  • Submitted

answer

#include <bits/stdc++.h>
#define all(a) begin(a), end(a)
#define sz(a) (int) (a).size();
#define int long long
using namespace std;

const int N_MAX = 1e6 + 11;
int p[N_MAX], q[N_MAX];
bool vis[N_MAX];
void solve() {
    int n; cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
    }

    int c = 0;
    for (int i = 1; i <= n; i++) {
        if (!vis[i]) {
            vis[i] = true;
            q[++c] = i;
            int x = p[i];
            while (x != i) {
                vis[x] = true;
                q[++c] = x;
                x = p[x];
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        cout << q[i] << " \n"[i == n];
    }
}

int32_t main(){
    cin.tie(0); cout.tie(0)->sync_with_stdio(false);
    int t; cin >> t;
    while (t--) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 5660kb

input:

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

output:

1 2 3 4
5 2 6 1 0 0

result:

wrong answer Integer parameter [name=q] equals to 0, violates the range [1, 6] (test case 2)