Submission #54770028


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using pl = pair<ll, ll>;
constexpr ll INF = 1e9 + 7;
constexpr ll mod = 1e9 + 7;
constexpr ld eps = 1e-9;
const ld PI = acos(-1);

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    ll n;
    cin >> n;
    map<ll, ll> pos;
    vector<ll> a(n);
    for (ll i = 0; i < n; ++i) {
        cin >> a[i];
        --a[i];
        pos[a[i]] = i;
    }
    vector<pl> res;
    for (ll i = 0; i < n; ++i) {
        ll need = pos[i];
        if (need == i)continue;
        res.push_back({i, need});
        pos[a[i]] = need;
        pos[i] = i;
        swap(a[i], a[need]);
    }
    cout << res.size() << "\n";
    for(auto &[x,y] : res){
        cout << x + 1 << " " << y + 1 << "\n";
    }
    return 0;
}

Submission Info

Submission Time
Task C - Sort
User ZergTricky
Language C++ 20 (gcc 12.2)
Score 300
Code Size 840 Byte
Status AC
Exec Time 171 ms
Memory 21480 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 165 ms 21480 KiB
random_02.txt AC 134 ms 18864 KiB
random_03.txt AC 168 ms 21304 KiB
random_04.txt AC 12 ms 5088 KiB
random_05.txt AC 168 ms 21272 KiB
random_06.txt AC 89 ms 13560 KiB
random_07.txt AC 1 ms 3488 KiB
random_08.txt AC 1 ms 3532 KiB
random_09.txt AC 67 ms 17140 KiB
random_10.txt AC 44 ms 12784 KiB
random_11.txt AC 96 ms 19380 KiB
random_12.txt AC 32 ms 9436 KiB
random_13.txt AC 171 ms 21372 KiB
random_14.txt AC 40 ms 8200 KiB
random_15.txt AC 168 ms 21276 KiB
random_16.txt AC 89 ms 13584 KiB
random_17.txt AC 132 ms 19384 KiB
random_18.txt AC 9 ms 4848 KiB
random_19.txt AC 132 ms 19188 KiB
random_20.txt AC 34 ms 8220 KiB
sample_01.txt AC 1 ms 3580 KiB
sample_02.txt AC 1 ms 3496 KiB
sample_03.txt AC 1 ms 3492 KiB