# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
781667 | 2023-07-13T09:32:43 Z | vjudge1 | Sorting (IOI15_sorting) | C++17 | 1000 ms | 449168 KB |
#include<bits/stdc++.h> using namespace std; #include "sorting.h" int c(vector<int> s){ int ans=0; vector<int> pos(s.size()); for(int i=0; i<pos.size(); i++) pos[s[i]]=i; for(int i=0; i<pos.size(); i++){ if(s[i]!=i){ ans++; swap(s[i], s[pos[i]]); swap(pos[s[i]], pos[s[pos[i]]]); } } return ans; } int findSwapPairs(int n, int S[], int m, int x[], int y[], int p[], int q[]) { vector<int> s(n); vector<vector<int>> a; for(int i = 0; i < n; i++) s[i] = S[i]; for(int i=0; i<n; i++){ vector<int> pos(n); for(int i=0; i<n; i++) pos[s[i]]=i; if(c(s)<=i){ int j=0; for(int l=i-1; l>=0; l--){ while(j<n&&s[j]==j) j++; if(j<n&&s[j]!=j){ q[l]=a[l][s[pos[j]]]; p[l]=a[l][s[j]]; swap(s[pos[j]], s[j]); //int f=pos[j], g=j; swap(pos[s[pos[j]]], pos[s[j]]); j++; } } // for(auto i: s) cout<<i<<" "; return i; } swap(s[x[i]], s[y[i]]); for(int i=0; i<n; i++) pos[s[i]]=i; a.push_back(pos); } return 0; } void f(){ freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); } /* int main() { f(); int N, M; cin >> N; int *S = (int*)malloc(sizeof(int) * (unsigned int)N); for (int i = 0; i < N; ++i) cin >> S[i]; cin >> M; int *X = (int*)malloc(sizeof(int) * (unsigned int)M), *Y = (int*)malloc(sizeof(int) * (unsigned int)M); for (int i = 0; i < M; ++i) { cin >> X[i] >> Y[i]; } int *P = (int*)malloc(sizeof(int) * (unsigned int)M), *Q = (int*)malloc(sizeof(int) * (unsigned int)M); int ans = findSwapPairs(N, S, M, X, Y, P, Q); cout<<ans<<"\n"; for (int i = 0; i < ans; ++i) cout<<P[i]<<" "<<Q[i]<<"\n"; return 0; } */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 296 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 304 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 296 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 296 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 304 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 296 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 1 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 296 KB | Output is correct |
3 | Correct | 1 ms | 312 KB | Output is correct |
4 | Correct | 1 ms | 308 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 296 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 304 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 296 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 1 ms | 340 KB | Output is correct |
13 | Correct | 1 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 296 KB | Output is correct |
15 | Correct | 1 ms | 312 KB | Output is correct |
16 | Correct | 1 ms | 308 KB | Output is correct |
17 | Correct | 1 ms | 340 KB | Output is correct |
18 | Correct | 1 ms | 212 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 1 ms | 212 KB | Output is correct |
21 | Correct | 3 ms | 1336 KB | Output is correct |
22 | Correct | 3 ms | 1364 KB | Output is correct |
23 | Correct | 4 ms | 1484 KB | Output is correct |
24 | Correct | 3 ms | 1236 KB | Output is correct |
25 | Correct | 2 ms | 724 KB | Output is correct |
26 | Correct | 2 ms | 952 KB | Output is correct |
27 | Correct | 3 ms | 1364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 34 ms | 13152 KB | Output is correct |
2 | Correct | 39 ms | 15268 KB | Output is correct |
3 | Correct | 37 ms | 13816 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 2 ms | 1492 KB | Output is correct |
6 | Correct | 4 ms | 3284 KB | Output is correct |
7 | Correct | 11 ms | 8884 KB | Output is correct |
8 | Correct | 36 ms | 14556 KB | Output is correct |
9 | Correct | 39 ms | 15048 KB | Output is correct |
10 | Correct | 37 ms | 15024 KB | Output is correct |
11 | Correct | 30 ms | 13644 KB | Output is correct |
12 | Correct | 12 ms | 8952 KB | Output is correct |
13 | Correct | 28 ms | 15528 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 34 ms | 13152 KB | Output is correct |
2 | Correct | 39 ms | 15268 KB | Output is correct |
3 | Correct | 37 ms | 13816 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 2 ms | 1492 KB | Output is correct |
6 | Correct | 4 ms | 3284 KB | Output is correct |
7 | Correct | 11 ms | 8884 KB | Output is correct |
8 | Correct | 36 ms | 14556 KB | Output is correct |
9 | Correct | 39 ms | 15048 KB | Output is correct |
10 | Correct | 37 ms | 15024 KB | Output is correct |
11 | Correct | 30 ms | 13644 KB | Output is correct |
12 | Correct | 12 ms | 8952 KB | Output is correct |
13 | Correct | 28 ms | 15528 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Execution timed out | 1096 ms | 449168 KB | Time limit exceeded |
16 | Halted | 0 ms | 0 KB | - |