Submission #52573101


Source Code Expand

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using ll = long long;
int N;
int a[200005];
int pos[200005];

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
    freopen("input","r",stdin);
#endif
    cin >> N;
    for (int i=1;i<=N;++i) {
        cin >> a[i];
        pos[a[i]] = i;
    }
    vector<pair<int, int>> ans;
    for (int i=1;i<N;++i) {
        if (pos[i] == i) continue;
        ans.emplace_back(i, pos[i]);
        int x = a[i];
        a[i] = i;
        a[pos[i]] = x;
        pos[x] = pos[i];
        pos[i] = i;
    }
    cout << ans.size() << '\n';
    for (auto &p:ans) cout << p.first << ' ' << p.second << '\n';
}

Submission Info

Submission Time
Task C - Sort
User seastar105
Language C++ 17 (gcc 12.2)
Score 300
Code Size 725 Byte
Status AC
Exec Time 29 ms
Memory 6796 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 23
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
random_01.txt AC 29 ms 6756 KiB
random_02.txt AC 24 ms 6576 KiB
random_03.txt AC 28 ms 6780 KiB
random_04.txt AC 4 ms 3740 KiB
random_05.txt AC 29 ms 6752 KiB
random_06.txt AC 17 ms 5036 KiB
random_07.txt AC 1 ms 3508 KiB
random_08.txt AC 1 ms 3508 KiB
random_09.txt AC 10 ms 5120 KiB
random_10.txt AC 6 ms 4604 KiB
random_11.txt AC 17 ms 5640 KiB
random_12.txt AC 7 ms 4304 KiB
random_13.txt AC 29 ms 6720 KiB
random_14.txt AC 8 ms 4212 KiB
random_15.txt AC 28 ms 6796 KiB
random_16.txt AC 17 ms 5116 KiB
random_17.txt AC 20 ms 5640 KiB
random_18.txt AC 3 ms 3756 KiB
random_19.txt AC 20 ms 5748 KiB
random_20.txt AC 7 ms 4208 KiB
sample_01.txt AC 1 ms 3516 KiB
sample_02.txt AC 1 ms 3364 KiB
sample_03.txt AC 1 ms 3560 KiB