Submission #725293

#TimeUsernameProblemLanguageResultExecution timeMemory
725293NemanjaSo2005Xor Sort (eJOI20_xorsort)C++14
40 / 100
50 ms912 KiB
#include<bits/stdc++.h> #define ll long long using namespace std; ll N,S,niz[1005],pniz[205],niz2[205],MaxO; bool pncmp(int a,int b){ return niz[a]<niz[b]; } struct slog{ int x,y; }pp; struct elem{ bool bit[205]; elem operator ^ (const elem &a){ elem r; for(int i=1;i<=N;i++) r.bit[i]=a.bit[i]^bit[i]; return r; } } sniz[205],zniz[205]; queue<slog> Q; void dodaj(int a,int b){ pp.x=a; pp.y=b; Q.push(pp); } void ispis(){ cout<<Q.size()<<endl; while(Q.size()){ pp=Q.front(); Q.pop(); cout<<pp.x<<" "<<pp.y<<endl; } exit(0); } void uradi(int a,int b){ sniz[a]=sniz[a]^sniz[b]; dodaj(a,b); } void pisibit(){ for(int i=N;i>=1;i--){ for(int j=1;j<=N;j++) cout<<sniz[j].bit[i]<<" "; cout<<endl; } } int main(){ // freopen("Input.txt","r",stdin); cin>>N>>S; for(int i=1;i<=N;i++) cin>>niz[i]; MaxO=40000; if(S==1){ for(int i=1;i<=N;i++) pniz[i]=i; sort(pniz+1,pniz+1+N,pncmp); for(int i=1;i<=N;i++){ sniz[pniz[i]].bit[i]=1; zniz[i].bit[i]=1; } for(int i=1;i<=N;i++) niz2[pniz[i]]=i; for(int i=1;i<=N;i++) for(int j=i;j<=N;j++){ if(niz2[j]!=i) continue; for(int k=j;k>i;k--){ swap(niz2[k],niz2[k-1]); uradi(k,k-1); uradi(k-1,k); }/* for(int k=j;k<N;k++) uradi(k+1,k); for(int k=j+1;k<N;k++) uradi(k+1,k);*/ break; } // pisibit(); for(int i=2;i<=N;i++) uradi(i-1,i); ispis(); return 0; } for(int step=(1<<19);step>=1;step/=2){ bool nemoj=true; for(int i=1;i<=N;i++) if(niz[i]&step) nemoj=false; if(nemoj) continue; for(int i=1;i<N;i++) if((niz[i]&step)>0 and (niz[i+1]&step)==0){ niz[i+1]^=niz[i]; dodaj(i+1,i); } for(int i=1;i<N;i++){ if(niz[i]&step){ niz[i]^=niz[i+1]; dodaj(i,i+1); } } N--; } ispis(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...