답안 #774825

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
774825 2023-07-06T03:51:01 Z vjudge1 Xor Sort (eJOI20_xorsort) C++17
25 / 100
79 ms 12500 KB
#include <bits/stdc++.h>

using namespace std;

int n, s;
vector<pair<int, int>> v;
vector<int> valueToIndex, indexToValue;
vector<pair<int, int>> operations;

void performSwap(const int& i, const int& j)
{
    assert(max(i - j, j - i) == 1);
    operations.emplace_back(i, j);
    operations.emplace_back(j, i);
    operations.emplace_back(i, j);
}

int main()
{
    // freopen("inp.txt", "r", stdin);

    ios::sync_with_stdio(false);

    cin >> n >> s;
    v.resize(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i].first;
        v[i].second = i;
    }

    sort(v.begin(), v.end());

    valueToIndex.resize(n);
    indexToValue.resize(n);
    for (int i = 0; i < n; i++)
    {
        indexToValue[v[i].second] = i;
        valueToIndex[i] = v[i].second;
    }

    for (int i = 0; i < n; i++)
    {
        int x = valueToIndex[i];
        for (int i1 = x; i1 > i; i1--)
        {
            int index = valueToIndex[i];
            int otherIndex = valueToIndex[i] - 1;
            int prevValueAtIndex = i;
            int prevValueAtOtherIndex = indexToValue[otherIndex];

            valueToIndex[prevValueAtIndex] = otherIndex;
            indexToValue[otherIndex] = prevValueAtIndex;

            valueToIndex[prevValueAtOtherIndex] = index;
            indexToValue[index] = prevValueAtOtherIndex;

            performSwap(index, otherIndex);
        }
    }

    cout << operations.size() << '\n';
    for (auto &operation : operations)
        cout << operation.first + 1 << ' ' << operation.second + 1 << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 3 ms 704 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 4 ms 980 KB Output is correct
13 Correct 4 ms 964 KB Output is correct
14 Correct 4 ms 980 KB Output is correct
15 Correct 4 ms 960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 3 ms 704 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 4 ms 980 KB Output is correct
13 Correct 4 ms 964 KB Output is correct
14 Correct 4 ms 980 KB Output is correct
15 Correct 4 ms 960 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 4 ms 852 KB Output is correct
19 Correct 4 ms 852 KB Output is correct
20 Correct 4 ms 852 KB Output is correct
21 Correct 4 ms 828 KB Output is correct
22 Correct 4 ms 852 KB Output is correct
23 Correct 4 ms 852 KB Output is correct
24 Correct 3 ms 852 KB Output is correct
25 Correct 4 ms 852 KB Output is correct
26 Incorrect 7 ms 1360 KB Integer 59568 violates the range [0, 40000]
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 4 ms 852 KB Output is correct
5 Incorrect 79 ms 12500 KB Integer 764742 violates the range [0, 40000]
6 Halted 0 ms 0 KB -