# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
456322 | urosk | Xor Sort (eJOI20_xorsort) | C++14 | 12 ms | 1740 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
///sat
#include <chrono>
using namespace std::chrono;
#define vremestart auto start = high_resolution_clock::now();
#define vremeend auto stop = high_resolution_clock::now();
#define vremeispis auto duration = duration_cast<microseconds>(stop - start); cout << duration.count() << endl;
///sat
#define here cerr<<"---------------------------\n"
#define popcount(x) __builtin_popcount(x) ///broj bitova
#include <bits/stdc++.h>
#define ld double
#define ll long long
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define th third
#define fo fourth
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define rall(a) a.begin(),a.end(),greater<int>()
using namespace std;
void setIO(string inoutname)
{
freopen((inoutname+".in").c_str(),"r",stdin);
freopen((inoutname+".out").c_str(),"w",stdout);
}
ll gcd(ll a, ll b)
{
if(b==0) return a;
if(a==0) return b;
if(a>=b) return gcd(a%b,b);
return gcd(a,b%a);
}
#define maxn 1005
ll n,s;
ll a[maxn][30];
ll maxi[maxn];
vector<pll> ans;
void xor_(ll i,ll j){
for(ll k = 0;k<25;k++){
a[i][k]^=a[j][k];
}
for(ll k = 25;k>=0;k--){
if(a[i][k]!=0){
maxi[i] = k;
break;
}
}
ans.pb({i,j});
//cerr<<i<< " "<<j<<endl;
return;
}
ll dec(ll i){
ll ans = 0;
ll dv = 1;
for(ll j = 0;j<=19;j++){
if(a[i][j]==1) ans+=dv;
dv*=2;
}
return ans;
}
void tc(){
ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
cin >> n >> s;
ll x;
for(ll i = 1;i<=n;i++){
cin >> x;
ll j = 0;
while(x>0){
ll f = x%2;
a[i][j] = f;
x/=2;
if(f==1) maxi[i] = j;
j++;
}
}
/*for(ll i = 1;i<=n;i++){
for(ll j = 19;j>=0;j--) cout<<a[i][j];
cout<<endl;
}*/
//here;
ll m = n;
for(ll k = 25;k>=0;k--){
for(ll i = 1;i<m;i++){
if(a[i][k]==0) continue;
for(ll j = i;j<m;j++){
if(a[j+1][k]==0){
xor_(j+1,j);
}
}
for(ll j = i;j<m;j++){
xor_(j,j+1);
}
m--;
break;
}
//for(ll i = 1;i<=n;i++) cerr<<dec(i)<< " ";
//cerr<<endl;
}
//here;
cout<<sz(ans)<<endl;
for(pll p : ans){
cout<<p.fi<< " "<<p.sc<<endl;
}
/*for(ll i = 1;i<=n;i++){
for(ll j = 25;j>=0;j--) cout<<a[i][j];
cout<<endl;
}*/
}
int main(){
ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
//setIO("lol");
int t; t = 1;
while(t--){
tc();
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |