Submission #314789

# Submission time Handle Problem Language Result Execution time Memory
314789 2020-10-21T08:27:44 Z kylych03 Sorting (IOI15_sorting) C++14
0 / 100
2 ms 764 KB
#include"sorting.h"
#include<bits/stdc++.h>
//#include"grader.cpp"
using namespace std;
int n,s[800005],x[800005],y[800005],tmp[800005],pos[800005];
vector<pair<int,int>>res;
bool check(int m){
    int i;
    for(i=0;i<n;i++)tmp[i]=s[i];
    for(i=0;i<m;i++)swap(tmp[x[i]],tmp[y[i]]);
    for(i=0;i<n;i++)pos[tmp[i]]=i;
    vector<pair<int,int>>sw;
    res.clear();
    for(i=0;i<n;i++){
        if(pos[i]==i)continue;
        sw.push_back({tmp[i],tmp[pos[i]]});
        swap(tmp[pos[i]],tmp[i]);
        swap(pos[tmp[pos[i]]],pos[tmp[i]]);
    }

    if(sw.size()>m)return 0;
    for(i=0;i<n;i++)tmp[i]=s[i],pos[tmp[i]]=i;
    for(i=0;i<sw.size();i++){
        swap(tmp[x[i]],tmp[y[i]]);
        swap(pos[tmp[x[i]]],pos[tmp[y[i]]]);
        res.push_back({pos[sw[i].first],pos[sw[i].second]});
        swap(tmp[pos[sw[i].first]],tmp[pos[sw[i].second]]);
        swap(pos[tmp[pos[sw[i].first]]],pos[tmp[pos[sw[i].second]]]);
    }
    for(;i<m;i++)res.push_back({0,0});
    return 1;
}
int findSwapPairs(int N,int S[],int m,int X[],int Y[],int P[],int Q[]){
    n=N;
    int i;
    for(i=0;i<n;i++)s[i]=S[i];
    for(i=0;i<m;i++)x[i]=X[i];
    for(i=0;i<m;i++)y[i]=Y[i];

    check(m);
    for(i=0;i<m;i++)P[i]=res[i].first,Q[i]=res[i].second;
    return m;
}

Compilation message

sorting.cpp: In function 'bool check(int)':
sorting.cpp:21:17: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   21 |     if(sw.size()>m)return 0;
      |        ~~~~~~~~~^~
sorting.cpp:23:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for(i=0;i<sw.size();i++){
      |             ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 764 KB Output isn't correct
2 Halted 0 ms 0 KB -