답안 #540621

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
540621 2022-03-21T08:55:39 Z groshi 정렬하기 (IOI15_sorting) C++17
20 / 100
2 ms 468 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=0,kon=m+1,sre;
    int wynik=m;
    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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 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 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 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 Incorrect 0 ms 340 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 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 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Incorrect 0 ms 340 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Incorrect 2 ms 468 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Incorrect 2 ms 468 KB Output isn't correct
4 Halted 0 ms 0 KB -