Submission #641887

# Submission time Handle Problem Language Result Execution time Memory
641887 2022-09-17T18:36:23 Z manizare Xor Sort (eJOI20_xorsort) C++14
0 / 100
0 ms 212 KB
#include<bits/stdc++.h>
 
#define all(a) a.begin(),a.end()
#define pb push_back
#define int long long
using namespace std ;
 
const int maxn = 1e7 , maxq = 1e5+10 , mod = 998244353 ,inf = 1e18 ;
int a[maxn] ;

signed main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n , s ;
	cin >>n >> s;
	for(int i =1 ; i <= n ; i++){
		cin >> a[i];
	}
	vector <pair <int ,int >  > ans ;
	int r = n ;
	for(int i = 19 ; i >= 0 ; i--){
		for(int j =2 ;j <= n ; j++){
			int x = ((a[j] & (1<<i)) != 0) , y =((a[j-1] & (1<<i)) != 0) ;
			if(x==y && x==1){
				a[j-1]^=a[j];
				ans.pb({j-1,j});
			}else if(x!=y && x==0){
				ans.pb({j,j-1});
				a[j]^=a[j-1];
				ans.pb({j-1,j});
				a[j-1]^=a[j];
			}
		}
		if(((1<<i)&a[r]) !=0)r--;
	}
	cout << ans.size() << "\n";
	for(int i = 0 ; i< ans.size() ; i++){
		cout <<ans[i].first << " " << ans[i].second << "\n" ;
	}
	cout << "\n";
	return 0 ; 
}

Compilation message

xorsort.cpp: In function 'int main()':
xorsort.cpp:36:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |  for(int i = 0 ; i< ans.size() ; i++){
      |                  ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Not sorted
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Not sorted
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Not sorted
2 Halted 0 ms 0 KB -