답안 #1089327

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1089327 2024-09-16T09:59:57 Z vjudge1 Xor Sort (eJOI20_xorsort) C++17
0 / 100
0 ms 348 KB
#include "bits/stdc++.h"
using namespace std;

#define int long long
#define endl endl

const int mod = 1e9 + 7;
const int maxn = 10005;

int n, s, arr[maxn];
vector < pair < int, int >> ans;
void s1()
{
   for(int i = n - 1; i >= 0; i--)
   {
       int mx = -1;
       for(int j = 0; j <= i; j++) if(mx == -1 || arr[mx] < arr[j]) mx = j;

       for(int j = 0; j < i; j++) ans.push_back({j, j + 1});

       for (int j = mx + 1; j <= i; j++) ans.push_back({j, j - 1});
       
       for (int j = mx - 2; j >= 0; j--) ans.push_back({j, j + 1});
       
       for (int j = mx; j + 1 < n; j++) swap(arr[j], arr[j + 1]);
       
   }
    for (int i = n - 2; i >= 0; --i) ans.push_back({i, i + 1});
}

void s2()
{
    for(int i = 19; i >= 0; i--)
    {
        for(int j = 0; j < n - 1; j++)
        {
            if(arr[j + 1] >= (1 << (i + 1))) break;
            if(!(arr[j] & (1 << i))) continue;
            if(!(arr[j + 1] & (1 << i))) ans.push_back({j + 1, j}), arr[j + 1] ^= arr[j];

            ans.push_back({j, j + 1});
            arr[j] ^= arr[j + 1];
        }
    }
}

void solve()
{
    cin >> n >> s;

    for(int i = 0; i < n; i++) cin >> arr[i];

    if(s == 1) s1();
    else s2();

    cout << ans.size() << endl;
    for(auto [i, j] : ans) cout << i << " " << j << endl;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int tt = 1;
    //cin >> tt;

    while(tt--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Integer 0 violates the range [1, 5]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Integer 0 violates the range [1, 5]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Integer 0 violates the range [1, 5]
2 Halted 0 ms 0 KB -