Submission #389604

# Submission time Handle Problem Language Result Execution time Memory
389604 2021-04-14T09:13:38 Z faresbasbs Sorting (IOI15_sorting) C++14
20 / 100
2 ms 716 KB
#include <bits/stdc++.h>
#include "sorting.h"
using namespace std;
vector<int> v,v2,st,e,l,r;
bool seen[200001];
int n,rt;

void dfs(int curr){
    if(curr != rt){
        l.push_back(rt);
        r.push_back(curr);
    }
    seen[curr] = 1;
    if(!seen[v2[curr]]){
        dfs(v2[curr]);
    }
}

bool work(int mid){
    memset(seen,0,sizeof seen);
    l.clear(),r.clear();
    v2 = v;
    for(int i = 0 ; i <= mid-1 ; i += 1){
        swap(v2[st[i]],v2[e[i]]);
    }
    int num = n;
    for(int i = 0 ; i < n ; i += 1){
        if(seen[i]){
            continue;
        }
        num -= 1;
        rt = i;
        dfs(i);
    }
    return num <= mid;
}

int findSwapPairs(int N , int s[] , int m , int x[] , int y[] , int p[] , int q[]){
    n = N;
    for(int i = 0 ; i < n ; i += 1){
        v.push_back(s[i]);
    }
    for(int i = 0 ; i < m ; i += 1){
        st.push_back(x[i]) , e.push_back(y[i]);
    }
    int first = -1 , last = m;
    while(last-first > 1){
        int mid = (first+last)/2;
        if(work(mid)){
            last = mid;
        }else{
            first = mid;
        }
    }
    for(int i = 0 ; i < (int)l.size() ; i += 1){
        p[i] = l[i] , q[i] = r[i];
    }
    return last;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 428 KB Output is correct
3 Correct 1 ms 428 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 428 KB Output is correct
3 Correct 1 ms 428 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 424 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 428 KB Output is correct
10 Correct 1 ms 560 KB Output is correct
11 Correct 1 ms 568 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Incorrect 1 ms 428 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 428 KB Output is correct
3 Correct 1 ms 428 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 424 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 428 KB Output is correct
10 Correct 1 ms 560 KB Output is correct
11 Correct 1 ms 568 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Incorrect 1 ms 428 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 716 KB Output isn't correct
2 Halted 0 ms 0 KB -