// clang-format off
#include <bits/stdc++.h>
using i64 = int64_t;
namespace space {
template <typename T> bool setmax(T &v, const T a) {
if (v < a) {
v = a;
return true;
} else {
return false;
}
}
int N, M;
std::vector<int> S, X, Y, P, Q;
std::vector<int> RS;
void swap(const int a, const int b) {
P.push_back(a);
Q.push_back(b);
std::swap(S[a], S[b]);
std::swap(RS[S[a]], RS[S[b]]);
}
int solve() {
for (int i = 0; i < N; ++i) {
const int pos_i = RS[i];
if (pos_i != i) swap(i, pos_i);
}
return (int)P.size();
}
int mfindSwapSpace(int n, int s[], int m, int x[], int y[], int rp[], int rq[]) {
N = n;
M = m;
S.resize(N);
X.resize(M);
Y.resize(M);
RS.resize(N);
for (int i = 0; i < N; ++i) {
S[i] = s[i];
RS[S[i]] = i;
}
for (int i = 0; i < M; ++i) {
X[i] = x[i];
Y[i] = y[i];
}
const int R = solve();
for (int i = 0; i < R; ++i) {
rp[i] = P[i];
rq[i] = Q[i];
}
return R;
}
}
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
return space::mfindSwapSpace(N, S, M, X, Y, P, Q);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
292 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
292 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
2 ms |
204 KB |
Output is correct |
10 |
Correct |
2 ms |
300 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
292 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
2 ms |
204 KB |
Output is correct |
10 |
Correct |
2 ms |
300 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |