#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
int get(vector<int> a,int target){
for(int i = 0;i<a.size();i++){
if(a[i] == target)
return i;
}
}
int findSwapPairs(int n, int s[], int m, int x[], int y[], int p[], int q[]) {
if(is_sorted(s,s+n))
return 0;
for(int i = 0;i<m;i++){
p[i] = q[i] = 0;
}
vector<int> final;
vector<int> now;
for(int i = 0;i<n;i++){
final.push_back(s[i]);
now.push_back(s[i]);
}
for(int i = 0;i<m;i++){
swap(final[x[i]],final[y[i]]);
}
for(int i = 0;i<n;i++){
swap(now[x[i]],now[y[i]]);
int ps1 = get(now,i);
int ps2 = get(now,final[i]);
p[i] = ps1;
q[i] = ps2;
swap(now[ps1],now[ps2]);
swap(final[i],final[get(final,i)]);
}
assert(is_sorted(final.begin(),final.end()));
return m;
}
Compilation message
sorting.cpp: In function 'int get(std::vector<int>, int)':
sorting.cpp:5:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
5 | for(int i = 0;i<a.size();i++){
| ~^~~~~~~~~
sorting.cpp:9:1: warning: control reaches end of non-void function [-Wreturn-type]
9 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
260 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
260 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
260 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
452 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
452 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |