답안 #464000

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
464000 2021-08-12T06:50:53 Z amunduzbaev Xor Sort (eJOI20_xorsort) C++14
0 / 100
1 ms 204 KB
#include "bits/stdc++.h"
using namespace std;

#define ar array

vector<ar<int, 2>> get(vector<int>& a, int b = 20){
	if(a.empty()) return {};
	vector<int> tmp;
	for(auto x : a) tmp.push_back(x>>b&1);
	
	vector<ar<int, 2>> rr;
	
	int i=0;
	while(i < (int)tmp.size() && tmp[i]) i++;
	if(i && i < (int)tmp.size()){
		i--;
		for(;i>0;i--){
			tmp[i] ^= 1;
			rr.push_back({i, i-1});
			rr.push_back({i, i+1});
			a[i] ^= a[i+1];
			a[i] ^= a[i-1];
		}
		
		rr.push_back({i, i+1});
		rr.push_back({i+1, i});
		rr.push_back({i, i+1});
		swap(tmp[i], tmp[i+1]);
		swap(a[i], a[i+1]);
	}
	
	for(int i=1;i+1<(int)tmp.size();i++){
		if(tmp[i] && tmp[i-1] == 0 && tmp[i+1]){
			tmp[i] ^= 1;
			rr.push_back({i, i+1});
			rr.push_back({i, i-1});
			a[i] ^= a[i+1];
			a[i] ^= a[i-1];
		} else if(tmp[i] && tmp[i+1] == 0){
			swap(tmp[i], tmp[i+1]);
			rr.push_back({i, i+1});
			rr.push_back({i+1, i});
			rr.push_back({i, i+1});
			swap(a[i], a[i+1]);
		}
	}
	
	if(b){
		if(tmp.back()) a.pop_back();
		vector<ar<int, 2>> tt = get(a, b - 1);
		rr.insert(rr.end(), tt.begin(), tt.end());
	}
	
	return rr;
}

void solve(){
	int n, s; cin>>n>>s;
	vector<int> a(n);
	for(auto& x : a) cin>>x;
	
	vector<ar<int, 2>> res = get(a);
	for(auto x : res) cout<<x[0] + 1<<" "<<x[1] + 1<<"\n";
	cout<<"\n";
}

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int t = 1;
	//~ cin>>t;
	while(t--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Not adjacent
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Not adjacent
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Not adjacent
2 Halted 0 ms 0 KB -