Submission #540631

# Submission time Handle Problem Language Result Execution time Memory
540631 2022-03-21T09:38:00 Z groshi Sorting (IOI15_sorting) C++17
100 / 100
498 ms 33648 KB
#include<iostream>
#include<utility>
#include "sorting.h"
using namespace std;
int t[1000000];
int gdzie[1000000];
int teraz[1000000];
int gdzie_teraz[1000000];
pair<int,int> zmiana[1000000];
int findSwapPairs(int n,int s[],int m,int x[],int y[],int p[],int q[])
{
    bool czy=0;
    p[0]=0;
    q[0]=1;
    for(int i=0;i<n;i++)
        if(s[i]!=i)
        {
            czy=1;
            break;
        }
    if(czy==0)
        return 0;
    int pocz=1,kon=m,sre;
    int wynik=m;
    while(pocz<kon)
    {
        sre=(pocz+kon)/2;
        for(int i=0;i<m;i++)
        {
            t[i]=0;
            gdzie[i]=0;
            teraz[i]=0;
            zmiana[i]={0,0};
            gdzie_teraz[i]=0;
        }
        //cout<<"sprawdzam "<<sre<<"\n";
        for(int i=0;i<n;i++)
        {
            t[i]=s[i];
            gdzie[s[i]]=i;
        }
        for(int i=0;i<sre;i++)
        {
            swap(t[x[i]],t[y[i]]);
            swap(gdzie[t[x[i]]],gdzie[t[y[i]]]);
        }
        for(int i=0;i<n;i++)
        {
            teraz[i]=i;
            gdzie_teraz[i]=i;
        }
        int zle=0;
        for(int i=sre-1;i>=0;i--)
        {
            while(zle<n && gdzie_teraz[zle]==gdzie[zle])
                zle++;
            if(zle>=n)
                continue;
            zmiana[i]={gdzie_teraz[zle],gdzie_teraz[t[gdzie_teraz[zle]]]};
            swap(teraz[gdzie_teraz[zle]],teraz[gdzie_teraz[t[gdzie_teraz[zle]]]]);
            swap(gdzie_teraz[zle],gdzie_teraz[t[gdzie_teraz[zle]]]);
            swap(gdzie[t[x[i]]],gdzie[t[y[i]]]);
            swap(t[x[i]],t[y[i]]);
            swap(gdzie_teraz[teraz[x[i]]],gdzie_teraz[teraz[y[i]]]);
            swap(teraz[x[i]],teraz[y[i]]);
        }
        bool ok=0;
        for(int i=0;i<n;i++)
            if(teraz[i]!=t[i])
                ok=1;
        //cout<<"ok "<<ok<<"\n";
        if(ok==0)
        {
            wynik=sre;
            kon=sre;
            for(int i=0;i<sre;i++)
            {
                p[i]=zmiana[i].first;
                q[i]=zmiana[i].second;
            }
        }
        else pocz=sre+1;
    }
    return wynik;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 444 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 444 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 964 KB Output is correct
22 Correct 2 ms 964 KB Output is correct
23 Correct 2 ms 968 KB Output is correct
24 Correct 2 ms 852 KB Output is correct
25 Correct 2 ms 952 KB Output is correct
26 Correct 2 ms 852 KB Output is correct
27 Correct 2 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 584 KB Output is correct
2 Correct 2 ms 528 KB Output is correct
3 Correct 2 ms 580 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 2 ms 584 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 2 ms 584 KB Output is correct
13 Correct 2 ms 516 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 584 KB Output is correct
2 Correct 2 ms 528 KB Output is correct
3 Correct 2 ms 580 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 2 ms 584 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 2 ms 584 KB Output is correct
13 Correct 2 ms 516 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 315 ms 29672 KB Output is correct
16 Correct 374 ms 30308 KB Output is correct
17 Correct 457 ms 32024 KB Output is correct
18 Correct 41 ms 13308 KB Output is correct
19 Correct 311 ms 31516 KB Output is correct
20 Correct 328 ms 32336 KB Output is correct
21 Correct 326 ms 32372 KB Output is correct
22 Correct 319 ms 27468 KB Output is correct
23 Correct 361 ms 33124 KB Output is correct
24 Correct 490 ms 32656 KB Output is correct
25 Correct 474 ms 32228 KB Output is correct
26 Correct 312 ms 32336 KB Output is correct
27 Correct 269 ms 31492 KB Output is correct
28 Correct 454 ms 32588 KB Output is correct
29 Correct 427 ms 32024 KB Output is correct
30 Correct 200 ms 31412 KB Output is correct
31 Correct 436 ms 32816 KB Output is correct
32 Correct 325 ms 31996 KB Output is correct
33 Correct 462 ms 32608 KB Output is correct
34 Correct 401 ms 32576 KB Output is correct
35 Correct 295 ms 30988 KB Output is correct
36 Correct 94 ms 30668 KB Output is correct
37 Correct 498 ms 33648 KB Output is correct
38 Correct 462 ms 32204 KB Output is correct
39 Correct 460 ms 32384 KB Output is correct