Submission #540615

# Submission time Handle Problem Language Result Execution time Memory
540615 2022-03-21T08:41:45 Z groshi Sorting (IOI15_sorting) C++17
0 / 100
2 ms 512 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;
    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,ostd;
    int wynik=0;
    while(pocz<kon)
    {
        sre=(pocz+kon)/2;
        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)
                break;
            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;
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:21:26: warning: unused variable 'ostd' [-Wunused-variable]
   21 |     int pocz=1,kon=m,sre,ostd;
      |                          ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 316 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 340 KB Expected integer, but "sprawdzam" found
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 316 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 340 KB Expected integer, but "sprawdzam" found
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Incorrect 0 ms 340 KB Expected integer, but "sprawdzam" found
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 316 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 340 KB Expected integer, but "sprawdzam" found
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 512 KB Expected integer, but "sprawdzam" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 512 KB Expected integer, but "sprawdzam" found
2 Halted 0 ms 0 KB -