답안 #372869

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
372869 2021-03-02T07:11:06 Z Traduttore Xor Sort (eJOI20_xorsort) C++14
0 / 100
1 ms 364 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define pll pair <ll,ll>
#define F first
#define S second
#define int ll
#define pb push_back
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
using namespace __gnu_pbds;
typedef tree <pll,null_type,less <pll>,rb_tree_tag,tree_order_statistics_node_update> orduk;
typedef tree <ll,null_type,less <ll>,rb_tree_tag,tree_order_statistics_node_update> orduk2;
ll n;
vector <ll> a;
inline void init() {
    cin>>n;
    a.resize(n);
    for (int i = 0;i < n;i++)
        cin>>a[i];
}
vector <pll> ans;
inline void output() {
    cout<<ans.size()<<'\n';
    for (auto to:ans)
        cout<<to.F<<" "<<to.S<<'\n';
    exit(0);
}
inline void solve() {
    while (ans.size() < n * (n - 1) / 2) {
        bool found = true;
        for (int i = 0;i < n - 1;i++)
        if (a[i] > a[i + 1]) {
            ans.pb({i + 2,i + 1});
            a[i + 1]^=a[i];
            ans.pb({i + 1,i + 2});
            a[i]^=a[i + 1];
            ans.pb({i + 2,i + 1});
            a[i + 1]^=a[i];
            found = false;
            break;
        }
        if (found == true) break;
    }
}

int32_t main() {
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
IOS;
int m;
m = 10;
m-=9;
while (m--)
{
    init();
    solve();
    output();
}
}
/*written by Traduttore*/
/*waiting for a miracle...*/

Compilation message

xorsort.cpp: In function 'void solve()':
xorsort.cpp:32:23: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   32 |     while (ans.size() < n * (n - 1) / 2) {
      |            ~~~~~~~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Not sorted
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Not sorted
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Not sorted
2 Halted 0 ms 0 KB -