Submission #408787

# Submission time Handle Problem Language Result Execution time Memory
408787 2021-05-19T15:58:45 Z MDario Sorting (IOI15_sorting) C++11
20 / 100
2 ms 1100 KB
#include "sorting.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
int n, s[200001], m, x[600001], y[600001];
bool f(ll xf){
    int s1[200001];
    for(int i=0; i<n; i++){
        s1[i]=s[i];
    }
    int c=0;
    for(int i=0; i<xf; i++){
        swap(s1[x[i]], s1[y[i]]);
    }
    for(int i=0; i<n; i++){
        while(s1[i]!=i){
            c++;
            swap(s1[i], s1[s1[i]]);
        }
    }
    return (c<=xf);
}
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    n=N;
    m=M;
    bool b=1;
    for(int i=0; i<n; i++){
        s[i]=S[i];
        if(s[i]!=i)b=0;
    }
    if(b)return 0;
    for(int i=0; i<m; i++){
        x[i]=X[i];
        y[i]=Y[i];
    }
    if(f(1)){
        swap(s[x[0]], s[y[0]]);
        for(int i=0; i<n; i++){
            if(s[i]!=i){
                P[0]=i;
                Q[0]=s[i];
                swap(s[i], s[s[i]]);
            }
        }
        return 1;
    }
    int l=1, r=m+1, mid=0;
    while(l+1<r){
        mid=(l+r)/2;
        if(f(mid)){
            r=mid;
        }
        else l=mid;
    }
    int c=0;
    for(int i=0; i<=l; i++){
        swap(s[x[i]], s[y[i]]);
    }
    for(int i=0; i<n; i++){
        while(s[i]!=i){
            P[c]=i;
            Q[c]=s[i];
            c++;
            swap(s[i], s[s[i]]);
        }
    }
    for(int i=c; i<=l; i++){
        P[i]=0;
        Q[i]=0;
    }
	return l+1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 2 ms 972 KB Output is correct
7 Correct 1 ms 1100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 2 ms 972 KB Output is correct
7 Correct 1 ms 1100 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 1100 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
12 Correct 1 ms 1100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 1100 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 2 ms 972 KB Output is correct
7 Correct 1 ms 1100 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 1100 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
12 Correct 1 ms 1100 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Incorrect 1 ms 1100 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1100 KB Output isn't correct
2 Halted 0 ms 0 KB -