Submission #712126

# Submission time Handle Problem Language Result Execution time Memory
712126 2023-03-18T07:45:33 Z neki Sorting (IOI15_sorting) C++14
0 / 100
2 ms 440 KB
#include <bits/stdc++.h>
#include "sorting.h"
#define vc vector
 
using namespace std;
 
int findSwapPairs(int n, int s[], int m, int x[], int y[], int a[], int b[])
{
    int is[n];for(int i=0;i<n;++i) is[s[i]]=i;
    int l=0, r=m-1;
    while(l<r){
        int mid=(l+r)/2, j=0;
        {
            int p[n], ip[n], z[n], iz[n];
            for(int i=0;i<n;++i) p[i]=i, z[i]=iz[i]=i;
            for(int i=mid;i>=0;--i) swap(p[x[i]], p[y[i]]);
			for(int i=0;i<n;++i) ip[p[i]]=i;
            
            for(int i=mid;i>=0;--i){
                while(j<n && j==s[p[iz[j]]]) ++j;
                if(j<n) a[i]=iz[j], b[i]=ip[is[j]];
                else a[i]=b[i]=0;
                
                swap(ip[p[x[i]]], ip[p[y[i]]]);
                swap(p[x[i]], p[y[i]]);
                
                swap(iz[z[a[i]]], iz[z[b[i]]]);
                swap(z[a[i]], z[b[i]]);
                swap(iz[z[x[i]]], iz[z[y[i]]]);
                swap(z[x[i]], z[y[i]]);
            }
        }
        if(j==n) r=mid;
        else l=mid+1;
    }
    int j=0;
    {
        int p[n], ip[n], z[n], iz[n];
        for(int i=0;i<n;++i) p[i]=i, z[i]=iz[i]=i;
        for(int i=l;i>=0;--i) swap(p[x[i]], p[y[i]]);
		for(int i=0;i<n;++i) ip[p[i]]=i;
        
        for(int i=l;i>=0;--i){
            while(j<n && j==s[p[iz[j]]]) ++j;
            if(j<n) a[i]=iz[j], b[i]=ip[is[j]];
            else a[i]=b[i]=0;
            
            swap(ip[p[x[i]]], ip[p[y[i]]]);
            swap(p[x[i]], p[y[i]]);
            
            swap(iz[z[a[i]]], iz[z[b[i]]]);
            swap(z[a[i]], z[b[i]]);
            swap(iz[z[x[i]]], iz[z[y[i]]]);
            swap(z[x[i]], z[y[i]]);
        }
    }
    return l;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 296 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 296 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 296 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 440 KB Output isn't correct
2 Halted 0 ms 0 KB -