답안 #448746

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
448746 2021-08-01T11:10:53 Z prvocislo Xor Sort (eJOI20_xorsort) C++17
100 / 100
9 ms 1020 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

const int maxn = 1005;
vector<int> a(maxn);
vector<pair<int, int> > v;
void go(int x, int y) { a[x] ^= a[y]; v.push_back({ x, y }); }
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, s; cin >> n >> s;
    for (int i = 0; i < n; i++) cin >> a[i];
    if (s == 1)
    {
        vector<int> b = a; b.resize(n);
        for (int i = n - 1; i > 0; i--)
        {
            for (int j = 0; j <= i && j < n - 1; j++) go(j, j + 1);
            int mi = max_element(b.begin(), b.end()) - b.begin();
            for (int j = mi; j < i; j++) go(j + 1, j);
            for (int j = mi - 1; j > 0; j--) go(j - 1, j);
            b.erase(b.begin() + mi);
        }
        go(0, 1);
    }
    else
    {
        int m = n;
        for (int b = 19; b >= 0; b--)
        {
            int l = -1;
            for (int i = 0; i < m; i++) if (a[i] & (1 << b))
            {
                l = i;
                break;
            }
            if (l == -1) continue;
            for (int i = l; i < m - 1; i++)
                if (!(a[i + 1] & (1 << b))) go(i + 1, i);
            for (int i = l; i < m - 1; i++) go(i, i + 1);
            m--;
        }
    }
    cout << v.size() << "\n";
    for (pair<int, int> i : v) cout << i.first+1 << " " << i.second+1 << "\n";
    //for (int i = 0; i < n; i++) cout << a[i] << " ";
    //cout << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 5 ms 720 KB Output is correct
5 Correct 5 ms 720 KB Output is correct
6 Correct 5 ms 720 KB Output is correct
7 Correct 5 ms 720 KB Output is correct
8 Correct 5 ms 720 KB Output is correct
9 Correct 5 ms 748 KB Output is correct
10 Correct 5 ms 720 KB Output is correct
11 Correct 5 ms 720 KB Output is correct
12 Correct 5 ms 720 KB Output is correct
13 Correct 5 ms 720 KB Output is correct
14 Correct 5 ms 720 KB Output is correct
15 Correct 5 ms 720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 5 ms 720 KB Output is correct
5 Correct 5 ms 720 KB Output is correct
6 Correct 5 ms 720 KB Output is correct
7 Correct 5 ms 720 KB Output is correct
8 Correct 5 ms 720 KB Output is correct
9 Correct 5 ms 748 KB Output is correct
10 Correct 5 ms 720 KB Output is correct
11 Correct 5 ms 720 KB Output is correct
12 Correct 5 ms 720 KB Output is correct
13 Correct 5 ms 720 KB Output is correct
14 Correct 5 ms 720 KB Output is correct
15 Correct 5 ms 720 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 5 ms 720 KB Output is correct
18 Correct 8 ms 976 KB Output is correct
19 Correct 8 ms 976 KB Output is correct
20 Correct 8 ms 976 KB Output is correct
21 Correct 8 ms 976 KB Output is correct
22 Correct 8 ms 976 KB Output is correct
23 Correct 8 ms 976 KB Output is correct
24 Correct 8 ms 976 KB Output is correct
25 Correct 9 ms 976 KB Output is correct
26 Correct 8 ms 976 KB Output is correct
27 Correct 8 ms 1020 KB Output is correct
28 Correct 8 ms 976 KB Output is correct
29 Correct 8 ms 976 KB Output is correct
30 Correct 8 ms 976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 6 ms 848 KB Output is correct
6 Correct 6 ms 848 KB Output is correct
7 Correct 6 ms 848 KB Output is correct
8 Correct 7 ms 848 KB Output is correct
9 Correct 6 ms 848 KB Output is correct
10 Correct 6 ms 848 KB Output is correct
11 Correct 6 ms 848 KB Output is correct
12 Correct 7 ms 848 KB Output is correct
13 Correct 6 ms 952 KB Output is correct
14 Correct 7 ms 844 KB Output is correct
15 Correct 8 ms 976 KB Output is correct