답안 #467162

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
467162 2021-08-21T19:41:52 Z TlenekWodoru Xor Sort (eJOI20_xorsort) C++14
60 / 100
1000 ms 12612 KB
#include <bits/stdc++.h>
using namespace std;
int tab[1009];
bool zaj[2000000];
vector<pair<int,int>>odp;
int xorr(int a, int b)
{
    int u=1;
    int wynik=0;
    while(a>0||b>0)
    {
        if(a%2!=b%2)
        {
            wynik+=u;
        }
        a=a/2;
        b=b/2;
        u=u*2;
    }
    return wynik;
}
void swap_true(int a, int b)
{
    tab[a]=xorr(tab[a],tab[b]);
}
void swapp(int a, int b)
{
    /**swap_true(a,b);
    swap_true(b,a);
    swap_true(a,b);**/
    odp.push_back({a,b});
    odp.push_back({b,a});
    odp.push_back({a,b});
    swap(tab[a],tab[b]);
}
int main()
{ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    srand(time(0));
    int n,s;cin>>n>>s;
    for(int i=1;i<=n;i++)
    {
        cin>>tab[i];
        zaj[tab[i]]=1;
    } 
    for(int i=1;i<=n*3;i++)  
    {
        int a=(rand()%n)+1;
        int b=rand()%2;
        if(a==1||(b%2==1&&a!=n))
        {
            if(tab[a]>tab[a+1])
            {
                if(s==2||zaj[xorr(tab[a],tab[a+1])]==0)
                {
                    odp.push_back({a,a+1});
                    zaj[tab[a]]=0;
                    swap_true(a,a+1);
                    zaj[tab[a]]=1;
                } 
            }
        }
        else
        {
            if(tab[a]>tab[a-1])
            {
                if(s==2||zaj[xorr(tab[a],tab[a-1])]==0)
                {
                    odp.push_back({a,a-1});
                    zaj[tab[a]]=0;
                    swap_true(a,a-1);
                    zaj[tab[a]]=1;
                }
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        int minn=2000000000;
        int ind=-1;
        for(int j=i;j<=n;j++)
        {
            if(tab[j]<minn)
            {
                minn=tab[j];
                ind=j;
            }
        }
        for(int j=ind;j-1>=i;j--)
        {
            swapp(j,j-1);
        }
    }
    cout<<odp.size()<<endl;
    for(int i=0;i<odp.size();i++)
    {
        cout<<odp[i].first<<" "<<odp[i].second<<endl;
    }
    /**for(int i=1;i<=n;i++)
    {
        cout<<tab[i]<<endl;
    }**/
    return 0;
}






Compilation message

xorsort.cpp: In function 'int main()':
xorsort.cpp:94:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |     for(int i=0;i<odp.size();i++)
      |                 ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 4 ms 588 KB Output is correct
4 Correct 26 ms 1228 KB Output is correct
5 Correct 29 ms 1356 KB Output is correct
6 Correct 27 ms 1336 KB Output is correct
7 Correct 27 ms 1348 KB Output is correct
8 Correct 28 ms 1348 KB Output is correct
9 Correct 30 ms 1392 KB Output is correct
10 Correct 29 ms 1356 KB Output is correct
11 Correct 21 ms 1284 KB Output is correct
12 Correct 35 ms 1232 KB Output is correct
13 Correct 35 ms 1228 KB Output is correct
14 Correct 34 ms 1232 KB Output is correct
15 Correct 37 ms 1344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 4 ms 588 KB Output is correct
4 Correct 26 ms 1228 KB Output is correct
5 Correct 29 ms 1356 KB Output is correct
6 Correct 27 ms 1336 KB Output is correct
7 Correct 27 ms 1348 KB Output is correct
8 Correct 28 ms 1348 KB Output is correct
9 Correct 30 ms 1392 KB Output is correct
10 Correct 29 ms 1356 KB Output is correct
11 Correct 21 ms 1284 KB Output is correct
12 Correct 35 ms 1232 KB Output is correct
13 Correct 35 ms 1228 KB Output is correct
14 Correct 34 ms 1232 KB Output is correct
15 Correct 37 ms 1344 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 30 ms 1364 KB Output is correct
18 Correct 52 ms 1732 KB Output is correct
19 Correct 50 ms 1688 KB Output is correct
20 Correct 51 ms 1692 KB Output is correct
21 Correct 50 ms 1604 KB Output is correct
22 Correct 52 ms 1652 KB Output is correct
23 Correct 49 ms 1608 KB Output is correct
24 Correct 52 ms 1704 KB Output is correct
25 Correct 51 ms 1612 KB Output is correct
26 Correct 66 ms 1616 KB Output is correct
27 Correct 62 ms 1636 KB Output is correct
28 Correct 63 ms 1812 KB Output is correct
29 Correct 59 ms 1552 KB Output is correct
30 Correct 61 ms 1540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 4 ms 588 KB Output is correct
4 Correct 51 ms 1688 KB Output is correct
5 Execution timed out 1095 ms 12612 KB Time limit exceeded
6 Halted 0 ms 0 KB -