Submission #318031

# Submission time Handle Problem Language Result Execution time Memory
318031 2020-10-31T09:16:44 Z wildturtle Sorting (IOI15_sorting) C++14
0 / 100
2 ms 620 KB
#include <bits/stdc++.h>
#include "sorting.h"
using namespace std;
int a,le,ri,ans,mid;
vector <int> S1,A;
vector < pair < int , int > > v;
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    le=0; ri=M; ans=-1;
    while(le<=ri) {
        mid=(le+ri)/2;
        for(int i=0;i<N;i++)
        S1[i]=S[i];
        for(int i=0;i<mid;i++) {
            swap(S1[X[i]],S1[Y[i]]);
        }
        for(int i=0;i<N;i++) {
            A[S1[i]]=i;
        }
        v.clear();
        for(int i=0;i<N;i++) {
            if(S1[i]==i) continue;
            v.push_back({i,S1[i]});
            swap(S1[i],S1[A[i]]);
            swap(A[i],A[S1[A[i]]]);   
        }
        a=v.size();
        if(a<=mid) {
            for(int i=0;i<N;i++) {
                S1[i]=S[i];
                A[S1[i]]=i;
            }
            for(int i=0;i<M;i++) {
                swap(A[S1[X[i]]],A[S1[Y[i]]]);
                swap(S1[X[i]],S1[Y[i]]);
                if(i<a) {
                    P[i]=A[v[i].first];
                    Q[i]=A[v[i].second];
                    swap(A[v[i].first],A[v[i].second]);
                    swap(S1[A[v[i].first]],S1[A[v[i].second]]);                    
                }
                else { P[i]=0; Q[i]=0; }
            }
            ri=mid-1;
            ans=mid;
        }
        else le=mid+1;
    }
    return ans;
}/*
int main() {
    findSwapPairs(5 , [4,3,2,1,0] , 6 , [0,1,2,3,0,1] , [1,2,3,4,1,2] , [] , [] );
}*/

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:26:17: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   26 |         a=v.size();
      |           ~~~~~~^~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 620 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 620 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -