# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
427215 |
2021-06-14T13:25:16 Z |
ollel |
Sorting (IOI15_sorting) |
C++17 |
|
4 ms |
716 KB |
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define rep(i,a,b) for(int i = a; i < b; i++)
#define pb push_back
#define lso(x) x&(-x)
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
int N;
bool sorted(int s[]) {
rep(i,0,N) if (s[i] != i) return false;
return true;
}
int findSwapPairs(int n, int S[], int M, int X[], int Y[], int P[], int Q[]) {
N = n;
int r = 0;
while (!sorted(S)) {
swap(S[X[r]], S[Y[r]]);
if (sorted(S)) {P[r] = Q[r] = 0; return r + 1;}
bool f = false;
for (int mx = 4; mx >= 1; mx--) {
rep(i,0,n) {
rep(j, 1, mx) {
if (S[i] != X[r + i] && S[i] != Y[r + i]) {
P[r] = i;
Q[r] = S[i];
swap(S[i], S[S[i]]);
f = true;
break;
}
if (f) break;
}
if (f) break;
}
if (f) break;
}
if (!f) P[r] = Q[r] = 0;
r++;
}
return r;
}
//
// int main() {
// int n = 5;
// int S[] = {4, 3, 1, 0, 2};
// int M;
// int X[25] = {1, 2, 3, 4, 0}, Y[25] = {4, 0, 1, 2, 0}, P[25], Q[25];
// cout << findSwapPairs(n, S, M, X, Y, P, Q) << endl;
// rep (i, 0, 25) cout << P[i] << " " << Q[i] << endl;
// }
Compilation message
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:19:39: warning: unused parameter 'M' [-Wunused-parameter]
19 | int findSwapPairs(int n, int S[], int M, int X[], int Y[], int P[], int Q[]) {
| ~~~~^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Runtime error |
2 ms |
460 KB |
Execution killed with signal 11 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Runtime error |
2 ms |
460 KB |
Execution killed with signal 11 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
716 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
716 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |