Submission #466420

#TimeUsernameProblemLanguageResultExecution timeMemory
466420daisyXor Sort (eJOI20_xorsort)C++17
100 / 100
11 ms1008 KiB
#include<iostream> #include<vector> #include<algorithm> #define endl '\n' using namespace std; int n,s,p[1005]; pair<int,int> m[1005]; vector< pair<int,int> > v; bool cmp(pair<int,int> a, pair<int,int> b) { return a.first>b.first; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>s; for(int i=1;i<=n;i++){ cin>>m[i].first; m[i].second=i; } if(s==2){ for(int i=1;i<=(1<<20);i*=2) { for(int j=1;j<n;j++) { if((i&m[j].first)) { if(!(i&m[j+1].first)) { v.push_back({j+1,j}); m[j+1].first^=m[j].first; } v.push_back({j,j+1}); m[j].first^=m[j+1].first; } } } } if(s==1){ sort(m+1,m+n+1,cmp); int t; for(int i=1;i<=n;i++) { t=m[i].second-p[m[i].second]; for(int j=m[i].second+1;j<=n;j++) p[j]++; for(int j=1;j<=min(n-1,n-i+1);j++) { v.push_back({j,j+1}); } for(int j=t+1;j<=n-i+1;j++) { v.push_back({j,j-1}); } for(int j=t-2;j>=1;j--) { v.push_back({j,j+1}); } } } cout<<v.size()<<endl; for(int i=0;i<v.size();i++) { cout<<v[i].first<<" "<<v[i].second<<endl; } }

Compilation message (stderr)

xorsort.cpp: In function 'int main()':
xorsort.cpp:72:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |    for(int i=0;i<v.size();i++)
      |                ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...