답안 #465804

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
465804 2021-08-16T18:58:35 Z daisy Xor Sort (eJOI20_xorsort) C++17
0 / 100
1 ms 204 KB
#include<iostream>
#include<vector>
#define endl '\n'
using namespace std;
pair<int,int> m[1005];
vector< pair<int,int> > v;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n,s,b=0;
    cin>>n>>s;

    for(int i=1;i<=n;i++){
        cin>>m[i].first;
        m[i].second=i;
     }

    for(int i=(1<<20);i>=1;i/=2)
    {
        for(int j=1;j<n;j++)
        {
            if(((i&(m[j].first)) && m[j+1].first<=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);
            }
        } //for(int i=1;i<=n;i++) cout<<m[i].first<<" ";cout<<endl;
    }

  cout<<v.size()<<endl;

   for(int i=0;i<v.size();i++)
   {
       cout<<v[i].first<<" "<<v[i].second<<endl;
   }

}

Compilation message

xorsort.cpp: In function 'int main()':
xorsort.cpp:41: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]
   41 |    for(int i=0;i<v.size();i++)
      |                ~^~~~~~~~~
xorsort.cpp:13:13: warning: unused variable 'b' [-Wunused-variable]
   13 |     int n,s,b=0;
      |             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Not sorted
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Not sorted
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Not sorted
3 Halted 0 ms 0 KB -